[英]Using java.util.concurrent.executors
I am trying to write a service which runs a module as a separate thread. 我正在尝试编写一个将模块作为单独的线程运行的服务。 The service needs to provide interface to start running a module by taking a Runnable/Callable as argument. 该服务需要通过将Runnable / Callable作为参数来提供开始运行模块的接口。 It should also provide graceful shutdown like logging the reason for failure and closing connections to db and stuff.(How to add this functionality ?) 它还应该提供正常的关闭,例如记录失败的原因以及关闭与db和stuff的连接。(如何添加此功能?)
I understand that java.util.concurrent.executors
is the right thing for me. 我知道java.util.concurrent.executors
对我来说是正确的。 But not able to join the things together. 但是无法将这些东西加在一起。 It would be great if someone could share a outline or nice tutorial for java.util.concurrent.executors
. 如果有人可以分享java.util.concurrent.executors
的大纲或很好的教程,那将是很棒的。
Perhaps you are assuming to much. 也许你是假设很多。 An Executor is created, you add tasks to it and can use shutdown when you have finished with it. 创建了一个Executor,您可以向其添加任务,并在完成后使用shutdown。 No magic required. 不需要魔法。 If you want to log errors/exceptions, use a try/catch block. 如果要记录错误/异常,请使用try / catch块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.