How to shut down all Executors when quitting an application?

前端 未结 5 1365
离开以前
离开以前 2021-01-11 23:36

According to Brian Goetz\'s Java Concurrency in Practice JVM can\'t exit until all the (nondaemon) threads have terminated, so failing to shut down an Executor could pre

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-11 23:59

    You can also provide an implementation of ThreadFactory that marks created threads as daemon threads. I prefer a clean shutdown mechanism (with lifecycle methods) but there are cases where you don't need guarantees about the state/completion of uncompleted tasks when this can be appropriate.

提交回复
热议问题