简体   繁体   中英

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. It should also provide graceful shutdown like logging the reason for failure and closing connections to db and stuff.(How to add this functionality ?)

I understand that java.util.concurrent.executors is the right thing for me. 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 .

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. No magic required. If you want to log errors/exceptions, use a try/catch block.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM