+ 1
Can we keep track of threads in java? If so how do you determine last thread's task have ended?
9 Réponses
+ 6
You can add many threads at the time. You can set flag to identify that your last thread's task have been ended.
+ 3
+ 1
Sneha why do you have to create a separate thread for the same question?
You can continue your discussion here.
https://www.sololearn.com/Discuss/2157585/?ref=app
0
Have you come across the isAlive() in threads? You can use that to check whether the thread is alive or not.
Kindly let me know if you understood as how to use it or you want an example to understand.
0
I want to know bout the last task of the last thread
0
It would be better if you can share an example code with us because we cannot understand what type of task it is, or whether it is running inside a loop or how many threads are running concurrently.
All this information will make it easy to answer the question.
0
This is just a sample code.
final ExecutorService executor = Executors.newFixedThreadPool(5);
for (final object item : items) {
executor.submit(new Runnable() {
@Override
public void run() {
//Some random code
}
});
while(executor.isTerminated())
{
//wanted to know about the last task of last thread in this case
}
}
0
See if this helps-
https://www.tutorialspoint.com/javaexamples/thread_check.htm
0
I need a solution for threadpool executor service and not for threads.