In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what are the Java multithreading methods". In the daily operation, I believe that many people have doubts about the Java multithreading methods. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the questions of "what are the Java multithreading methods?" Next, please follow the editor to study!
First, the interrupt method is a way to let the thread exit.
Import java.util.*; public class TestInterrupt {public static void main (String [] args) {MyThread t = new MyThread (); t.start (); try {Thread.sleep (10000);} catch (InterruptedException I) {} t.interrupt () }} class MyThread extends Thread {public void run () {while (true) {try {System.out.println ("-" + new Date () + "-"); Thread.sleep (1000);} catch (InterruptedException I) {return }}
2. Join and yield methods
The current thread method body will not be executed until the run () method of t.join () / t is finished.
/ / that is, two threads become one thread.
T.yield (); / / pauses the currently executing thread object and executes other threads. Method is static
/ / which thread body executes this method and which thread gives in
Public class TestYield {public static void main (String [] args) {MyThread3 T1 = new MyThread3 ("T1"); MyThread3 T2 = new MyThread3 ("T2"); t1.start (); t2.start ();}} class MyThread3 extends Thread {MyThread3 (String s) {super (s);} public void run () {for (int I = 1teri)
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.