In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you Java to determine whether the thread ends what methods, I believe that most people do not understand, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!
Method 1
Determine whether the thread is active by the isAlive () method in the Thread class.
After the thread starts, it returns true as long as it does not finish running.
[note] if you just want to wait for other threads to finish running before continuing with the operation, you can execute t.join (), that is, suspend before t is finished.
Method 2
The number of active threads in the thread group of the current thread is determined by the Thread.activeCount () method, and the other threads are finished running at 1.
Method 3
Create a thread pool through the methods in java.util.concurrent.Executors, and use this thread pool to start threads. After starting all the threads to be started, execute the shutdown () method of the thread pool, which closes the thread pool after all threads have finished executing. Then use the isTerminated () method of the thread pool to determine whether the thread pool has been closed. The successful closure of the thread pool means that all threads have finished running.
Import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class Test {public static void main (String args []) throws InterruptedException {ExecutorService exe = Executors.newFixedThreadPool (50); for (int I = 1; I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.