class OneThread extends Thread{
public void run(Object t2){
System.out.println("第一个线程名:"+getName());
System.out.println("捕获的线程名:");
try{
wait();
}catch(InterruptedException e){}
}
}class TwoThread extends Thread{
public void run(){
System.out.println("第二个线程名:"+getName());
try{
Thread.sleep(5000);
}catch(InterruptedException e){
notifyAll();
}
}
}class Xiti_1104{
public static void main(String args[]){
OneThread t1=new OneThread();
TwoThread t2=new TwoThread();
t1.start();
t2.start();
}
}
public void run(Object t2){
System.out.println("第一个线程名:"+getName());
System.out.println("捕获的线程名:");
try{
wait();
}catch(InterruptedException e){}
}
}class TwoThread extends Thread{
public void run(){
System.out.println("第二个线程名:"+getName());
try{
Thread.sleep(5000);
}catch(InterruptedException e){
notifyAll();
}
}
}class Xiti_1104{
public static void main(String args[]){
OneThread t1=new OneThread();
TwoThread t2=new TwoThread();
t1.start();
t2.start();
}
}
小弟初学java,见笑了~~~呵呵
public void run(Object t2){
System.out.println("第一个线程名:"+getName());
System.out.println("捕获的线程名:"+TwoThread.currentThread().getName());
try{
wait();
}catch(InterruptedException e){}
}
}class TwoThread extends Thread{
public void run(){
System.out.println("第二个线程名:"+getName());
try{
Thread.sleep(5000);
}catch(InterruptedException e){
notifyAll();
}
}
}class Xiti_1104{
public static void main(String args[]){
OneThread t1=new OneThread();
TwoThread t2=new TwoThread();
t1.start();
t2.start();
}
}