↓こんなんでえぇですか?
public class ThreadTest {
public static void main(String[] args) {
Timing time = new Timing();
synchronized ( time ) {
time.start();
countUp();
}
}
public static void countUp(){
for (int i = 0; i < 20; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.print(i+"\n");
}
}
}
class Timing extends Thread{
public void run() {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized ( this ) {
System.out.print("スレッド終了\n");
}
System.exit(20);
}
}
|