multithreading - what will happen if I miss shutdown clause after declaring ExecutorService in java -


currently working on threading jobs using executorservice class , newfixedthreadpool command in java. when forgot execute shutdown() command after declaring executerservice instance, program never turned off. guessed executerservice may have internal command shutting down threads, since implements executor interface doesn't have explicit shutdown() commands. wondering happens inside executorservice class , related threads, such when threads dead, , happen shutdown() command forgotten. thank you.

executors.newfixedthreadpool creates thread pool given number of "core" threads, never shut down until shutdown() method called on thread pool.

look @ finalize method of threadpoolexecutor (the concrete class returned call executors.newfixedthreadpool):

protected void finalize() {   shutdown(); } 

so, if executorservice instance becomes eligible garbage collection, shutdown when finalize() called.

however, things related finalize() method, shouldn't rely upon being called @ particular time (if @ all).


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -