Can we keep track of threads in java? If so how do you determine last thread's task have ended? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can we keep track of threads in java? If so how do you determine last thread's task have ended?

4th Feb 2020, 4:25 PM
Sneha Sridhar
9 Answers
+ 6
You can add many threads at the time. You can set flag to identify that your last thread's task have been ended.
4th Feb 2020, 4:28 PM
A͢J
A͢J - avatar
4th Feb 2020, 6:11 PM
Zhenis Otarbay
Zhenis Otarbay - avatar
+ 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
4th Feb 2020, 4:46 PM
Avinesh
Avinesh - avatar
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.
4th Feb 2020, 4:49 PM
Avinesh
Avinesh - avatar
0
I want to know bout the last task of the last thread
4th Feb 2020, 4:59 PM
Sneha Sridhar
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.
4th Feb 2020, 5:03 PM
Avinesh
Avinesh - avatar
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      }        }
4th Feb 2020, 5:21 PM
Sneha Sridhar
4th Feb 2020, 5:23 PM
Avinesh
Avinesh - avatar
0
I need a solution for threadpool executor service and not for threads.
4th Feb 2020, 5:35 PM
Sneha Sridhar