简体   繁体   中英

How to identify a thread after running and then stop it in Grails with the executor plugin?

我正在使用executor插件,并且有多个作业正在执行,但是我想识别每个作业并停止我选择的作业,这可能吗?

I am not sure if there is an easier way but you could create a thread group for all of your executors and make the group a container of all your async tasks (executions). Then instead of passing a closure to the submit method of the plugin, you would create a named thread inside the ThreadGroup and pass the Thread to the submit. Make the TG being part of your spring context or make it global in one way or another. This way having a reference to the thread group you could get back to any active thread (and by extension to any async executions) by doing an enumerate on your TG and by inspecting the threads enumerated you could get to the thread's name, identifying any particular thread you want. You could then interrupt the thread.

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