When wil the new Thread() without reference be garbage collected

后端 未结 3 1382
耶瑟儿~
耶瑟儿~ 2020-12-19 06:45

In the below example, new Thread() doesnt have any reference. Is it possible that it be garbage collected below it is dead ? Also without extending Thread class or implement

3条回答
  •  余生分开走
    2020-12-19 06:52

    Your thread will be available for garbage collection once it has finished running. The end of your for loop does not influence it, as the for loop runs in a different thread.

    In answer to your second question, you are extending the Thread class by implementing your own run() function

提交回复
热议问题