In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
            
                    
                
2025-11-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to analyze the Java creation thread of the code, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
Java creation threads often appear in our coding, and there are a lot of problems bothering us when we use them. Let's first learn about the code related to the creation of threads in Java. I hope you can help.
Import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; / * Java threads: thread pool-* * @ author Administrator 2009-11-4 23:30:44 * / public class Test {public static void main (String [] args) {
Java creates threads that can be scheduled to run commands after a given delay or to execute them periodically. ScheduledExecutorService pool = Executors.newScheduledThreadPool (2); create and implement the Runnable interface object, Thread object also implements the Runnable interface
Thread T1 = new MyThread (); Thread T2 = new MyThread (); Thread T3 = new MyThread (); Thread t4 = new MyThread (); Thread t5 = new MyThread (); / / put threads into the pool to execute pool.execute (T1); pool.execute (T2); pool.execute (T3); / / use deferred execution style methods pool.schedule (T4, 10, TimeUnit.MILLISECONDS); pool.schedule (T5, 10, TimeUnit.MILLISECONDS) / / close thread pool pool.shutdown ();}} class MyThread extends Thread {@ Override public void run () {System.out.println (Thread.currentThread (). GetName () + "executing.") ;} import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; / * Java thread: thread pool-* * @ author Administrator 2009-11-4 23:30:44 * / public class Test {public static void main (String [] args) {
Java creates threads that can be scheduled to run commands after a given delay or to execute them periodically. ScheduledExecutorService pool = Executors.newScheduledThreadPool (2); create and implement the Runnable interface object, Thread object also implements the Runnable interface
Thread T1 = new MyThread (); Thread T2 = new MyThread (); Thread T3 = new MyThread (); Thread t4 = new MyThread (); Thread t5 = new MyThread (); / / put threads into the pool to execute pool.execute (T1); pool.execute (T2); pool.execute (T3); / / use deferred execution style methods pool.schedule (T4, 10, TimeUnit.MILLISECONDS); pool.schedule (T5, 10, TimeUnit.MILLISECONDS) / / close thread pool pool.shutdown ();}} class MyThread extends Thread {@ Override public void run () {System.out.println (Thread.currentThread (). GetName () + "executing.") ;}} Java code pool-1-thread-1 is being executed. Pool-1-thread-2 is executing. Pool-1-thread-1 is executing. Pool-1-thread-1 is executing. Pool-1-thread-2 is executing. Will Process finished with exit code 0 be helpful to you after reading the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





            
            About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.