In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what is the difference between All and Thread in idea". In daily operation, I believe that many people have doubts about the difference between All and Thread in idea. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "what is the difference between All and Thread in idea?" Next, please follow the editor to study!
All mode
All threads in will be blocked at the current location. Whoever comes first will block first. When blocking occurs, other threads will wait wherever they go at the current moment.
If you press F6 at this time, then all threads will block the code. If you press the recovery program to run F8 at this time, then the current thread will block the code and wait for the next thread to arrive. When blocking occurs, other threads will wait in place wherever they are currently executed.
Public class ThreadAndAllBreakApplication {public static void main (String [] args) {ThreadTest thread1 = new ThreadTest (); thread1.setName ("thread A"); thread1.start (); ThreadTest thread2 = new ThreadTest (); thread2.setName ("thread B"); thread2.start (); ThreadTest thread3 = new ThreadTest (); thread3.setName ("thread C"); thread3.start () }} class ThreadTest extends Thread {@ Override public void run () {System.out.println (Thread.currentThread (). GetName () + ": 1"); try {long millis = RandomUtil.randomLong (100,500); System.out.println (Thread.currentThread (). GetName () + "sleep:" + millis); Thread.sleep (millis) } catch (InterruptedException e) {e.printStackTrace ();} System.out.println (Thread.currentThread (). GetName () + ": 2"); System.out.println (Thread.currentThread (). GetName () + ": 3"); System.out.println (Thread.currentThread (). GetName () + ": the previous line of code that sets the breakpoint") / / current line sets breakpoint System.out.println (Thread.currentThread () .getName () + ": 4"); System.out.println (Thread.currentThread () .getName () + ": end")
Thread A: 1
Thread C: 1
Thread B: 1
Thread C Sleep: 283
Thread A Sleep: 340
Thread B Sleep: 127
Thread B: 2
Thread B: 3
Thread B: the previous line of code / / B that sets the breakpoint comes here, while other threads An and B are waiting in place, that is, An and B are sleeping.
Thread A: 2 / An executed to sleep before, now execute 2
Thread A: 3
Thread A: the previous line of code / A that sets the breakpoint comes here, while other threads B and C are waiting in place
Thread C: 2 / c executed to sleep before, now execute 2
Thread C: 3
Thread A: 4
Thread B: 4
Thread A: end
Thread C: the previous line of code / / C that sets the breakpoint comes here. If the breakpoint is not released, B will never output end and will wait in place. (this proves that when one thread is blocked by the All breakpoint, other threads will wait in place.)
Thread B: end
Thread C: 4
Thread C: end
Thread mode
All threads run to the breakpoint and block
If you press F6 at this time, the current thread will block the code and the other threads will not move.
If you press the recovery program to run F8 at this time, the current thread will debug by blocking the code and automatically switching to the next blocking thread.
At this point, the study on "what is the difference between All and Thread in idea" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.