62,634
社区成员




public class Threads4 {
public static void main(String[] args) throws Exception{
class Mythread implements Runnable{
Threads4 t4;
Mythread(Threads4 t4) {
this.t4=t4;
}
public void run() {
System.out.println("start "+Thread.currentThread().getId());
try {
t4.go();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("end "+Thread.currentThread().getId());
}
}
Threads4 t4=new Threads4();
Thread t1=new Thread(new Mythread(t4));
Thread t2=new Thread(new Mythread(t4));
t1.start();
Thread.sleep(2000);
t2.start();
}
public synchronized void go(){
System.out.println(Thread.currentThread().getId());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}
public class Threads4 {
public static void main(String[] args) throws Exception{
class Mythread implements Runnable{
Threads4 t4;
Mythread(Threads4 t4) {
this.t4=t4;
}
public void run() {
t4.go();
}
}
Threads4 t4=new Threads4();
Thread t1=new Thread(new Mythread(t4));
Thread t2=new Thread(new Mythread(t4));
t1.start();
// Thread.sleep(2000);
t2.start();
}
public synchronized void go(){
System.out.println("start go in thread :"+Thread.currentThread().getId());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
System.out.println("end go in thread :"+Thread.currentThread().getId());
}
}