Executor.execute()肯定挂起 [英] Executor.execute() hangs definitely

查看:97
本文介绍了Executor.execute()肯定挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在做nashorn,所以去阅读有关java.util.concurrent的内容.

Im doing nashorn lately and so went to read about the java.util.concurrent.

有一个问题,我可以运行像这样的简单执行程序:

Ive an issue where i can run simple executors like :

Executors.newFixedThreadPool();
new ThreadPoolExecutor();

代码片段运行,但是在任务结束后,控制台进程不会像挂起等待某些东西一样停止.

The snippets of code runs, but after the task is over the console process doesnt stop like if it hangs waiting something.

为什么会发生这种情况?

Any reason why this happens ?

推荐答案

那些执行程序正在生成非守护程序线程,这些线程阻止JVM退出.

Those executors are spawning non-daemon threads which are preventing the JVM from exiting.

尝试使用以下命令关闭执行器:

Try shutting down the executors when you are done with them using:

executor.shutdown();

这篇关于Executor.execute()肯定挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆