}
public void loop() {
// get a reference to the thread running this
Thread t = Thread.currentThread();
String name = t.getName();
System.out.println("just entered loop() - " + name);
for ( int i = 0; i < 10; i++ ) {
try {
Thread.sleep(2000);
} catch ( InterruptedException x ) {
// ignore
}
System.out.println("name=" + name);
}
System.out.println("about to leave loop() - " + name);
}
public static void main(String[] args) {
TwoThreadSleep tt = new TwoThreadSleep();
tt.setName("my worker thread");
tt.start();
// pause for a bit
共21页 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21