Reputation: 6474
In a java program, I am running same function across multiple threads. What I want to do is this--
Upvotes: 0
Views: 664
Reputation: 21883
Answers for
ThreadUtil
and inside have a static Set<Thread>
. You can add the threads you create to set and remove whenever the thread finishes executing.
Or you can extend from ThreadPoolExecutor
and override methods beforeExecute
, afterExecute
methods to do the same thing above. The you can use the set to get the running threads. You can use a map if you want to store and retrieve by name.ThreadLocal
class. See this post on how to use ThreadLocal
ThreadLocal
boolean stop
) in the thread to do this, and a method to set this flag to true
Upvotes: 1