Home > Back-end >  Java code daemon bosses to look at why zhang fei and guan yu
Java code daemon bosses to look at why zhang fei and guan yu

Time:01-20

Package Com. Wj. Demo03;

Public class TestDemo03 {
Public static void main (String [] args) {
MyTask mt=new MyTask ();
Thread th=new Thread (mt, "guan yu");

MyTask mt2=new MyTask ();
Thread th2=new Thread (mt, "zhang fei");
/* th2. SetPriority (Thread. MAX_PRIORITY);
Th2. SetPriority (10); */
Th. SetDaemon (true);
Th2. SetDaemon (true);
Th. The start ();
/* th. The join (); */

Th2. Start ();
for (int i=0; I<100; I++) {
System. The out. Println (" liu "+ I);
}
}
}
Package Com. Wj. Demo03;

Public class MyTask implements Runnable {
@ Override
Public void the run () {

for (int i=0; I<100; I++) {
/* the try {
Thread.sleep(1000);
{} catch InterruptedException (e)
e.printStackTrace();
} */
System. The out. Println (Thread. CurrentThread (). The getName () + ":" + I);
/* Thread. The yield (); */
}
}
}

CodePudding user response:

Try you to enlarge the for loop to 1 billion
Circular 100 too fast, the main thread in one fell swoop over, daemon thread followed over over
  • Related