I\'m comfortable with the idea of orderly shutdown on threads scheduled with an ExectuorService
; that is to say, calling shutdown
or shutdownNow<
is it bad practice to use daemon threads in a ExecutorService's thread pool?
If the tasks sent to that particular ExecutorService
are ok to be terminated abruptly, then why not, that's what daemon threads do. But generally, there are not many tasks that are ok to be terminated with no shutdown ceremonies at all, so you must know what you're doing if you opt to daemon threads.
finalize()
is called when an object is about to be garbage collected. There are no guarantees on when, if ever, any particular object will be GCd, and ThreadPoolExecutor
is no exception, so its finalize()
may or may not be called. The behavior depends on the particular JRE implementation, and even with the same implementation, may vary from time to time.