Why doesn't this thread pool get garbage collected?

前端 未结 6 595
长情又很酷
长情又很酷 2020-12-08 04:36

In this code example, the ExecutorService is used one and allowed to go out of scope.

public static void main(String[] args)
{
    ExecutorService executorSe         


        
6条回答
  •  醉酒成梦
    2020-12-08 05:01

    Because garbage collection is “non deterministic” ie you cannot predict when it will happen, you thus cannot predict exactly when the finalize method will run. You can only make Objects eligible for GC and suggest gc with System.gc() without any guarantee.

    Even worse threads are OS specific handled by the JVM and are hardly predictable...

提交回复
热议问题