public class SleepOtherThread {
public static void main(String[] args) throws
InterruptedException {
Runnable r = new Runnable() {
public void run() {
System.out.print(Thread.currentThread().getName());
}
};
Thread t1 = new Thread(r, "One ");
t1.start();
t1.sleep(2000);
Thread t2 = new Thread(r, "Two ");
t2.start();
t2.sleep(1000);
System.out.print("Main ");
}
}
What is the most likely result?
A.
Main One Two
B.
Main Two One
C.
One Two Main
D.
One Main Two
E.
Two Main One
Risposta: CWhat is the most likely result?
A.
Main One Two
B.
Main Two One
C.
One Two Main
D.
One Main Two
E.
Two Main One
One Two Main
Per capire cosa succede nel tempo vediamo uno schema. Le frecce vanno nel senso del tempo crescente:

Nessun commento:
Posta un commento