简体   繁体   English

使用java.util.concurrent.executors

[英]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.

相关问题 为什么Executors.newCachedThreadPool在提交期间抛出java.util.concurrent.RejectedExecutionException - Why does Executors.newCachedThreadPool throw java.util.concurrent.RejectedExecutionException during submit java.util.concurrent中 - java.util.concurrent 使用java.util.concurrent语义的Java并发支持 - Java concurrency support using java.util.concurrent semantics 使用java.util.concurrent API结束的线程 - Thread ending using java.util.concurrent API 如何使用 java.util.concurrent 包实现后台线程? - How to implement a background thread using java.util.concurrent package? 为什么使用数组而不是链表的java.util.concurrent.PriorityBlockingQueue - Why is java.util.concurrent.PriorityBlockingQueue using an array not a linked list 使用 java.util.concurrent.TimeUnit 在 JMETER 上显示 GroovyBugError - Using java.util.concurrent.TimeUnit shows GroovyBugError on JMETER 如何显示 java.util.concurrent.CompletionException 的 Stacktrace(使用 JavaFX) - How to show Stacktrace of java.util.concurrent.CompletionException (Using JavaFX) java.util.concurrent.RejectedExecutionException: - java.util.concurrent.RejectedExecutionException: 使用java.util.concurrent.Concurrent *容器时使用volatile有什么用? - What does using volatile when using a java.util.concurrent.Concurrent* containers provide?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM