I have a singleton class that is shared by some threads.
within a method of this singleton i want to create another thread to do some job (so any thread that uses this singleton can start the additional thread job)
Right now I start threads in simple way:
mSThread = new Thread(job that implements Runnable);
mSThread.start();
Thread mSThread is declared as class member, I don’t think that I need to keep reference to the threads so it’s ok that every time a new thread is created the reference will be lost
Is it ok to do what i did or i should use a different technique like thread pool?
It is not absolutely necessary to keep a reference to the thread object, so if you don’t need it for anything else, you don’t need to store it in a member variable; you can just start the thread and forget the reference.
Whether you should use a thread pool, depends on what exactly your application does, how often you expect to start new threads, etc.; without further information it’s hard to say whether this is worth it or not. If you do this, you’ll want to use the classes from the
java.util.concurrentpackage. Using anExecutorServiceyou can start background tasks in a thread pool.