Today, learning javase Multi-threading, sleeping sleep inside the problem is a bit disturbing:
Public classthread_06_stopsleep{ Public Static voidMain (string[] args) throws exception{Processor p=NewProcessor (); Thread T=NewThread (P); T.start ();//Thread.Sleep ( the);//Thread : Represents the same class as the current code, main () for(intI=0; I <Ten; ++i) {System. out. println (Thread.CurrentThread (). GetName () +"----->"+i); } P.run=false; }}classProcessor implements runnable{Boolean run=true; Public voidrun () { for(intI=0; I <Ten; ++i) { if(run) {//if run is false, then sleep will not execute. Try{Thread.Sleep ( +); }Catch(Exception e) {e.printstacktrace (); } System. out. println (Thread.CurrentThread (). GetName () +"----->"+i); }Else{System. out. println ("sleep, was awakened." ); return;//terminates the function, which is where the current thread is killed. } } }
But why did the next one come true when the output was finished? As follows:
Why there is a fifth time, not the fifth time has been false in the pass, seeking expert guidance maze!!
Yes, and I also because it is also a beginner, the article did not have any technical content, you want to reprint on the casual turn, but please add my link, OK?
Thread Multithreading Stopsleep order problem