First a little background. I got a warning in NetBeans told me not to start a new thread in a constructor. I have read that the reason for that is because the new thread might start and try to reference the object started the thread before the constructor is actually done making the object.
1.) For the sake of experimentation instead of using new Thread
and thread.start()
I tried ExecutorService
and I got no warning. Does this mean it is ok to create and start a new thread in a constructor if I use ExecutorService
?
2.) Also, if I have an ExecutorService
in the form of a cached thread pool will the creation of a new thread by the standard method of new Thread
and thread.start()
pull a thread from the cache pool (or cause it to create one if one is not available) or are those threads completely independent of the cached thread pool?