package test;
public class Test2 {
/**
* @param args
*/
public static void main(String[] args) {
new Test2();
}
public static Integer num = 20;
public Test2() {
myThreadClass1 thread1 = new myThreadClass1();
myThreadClass2 thread2 = new myThreadClass2();
Thread t1 = new Thread(thread1);
Thread t2 = new Thread(thread2);
t1.start();
t2.start();
}
class myThreadClass1 implements Runnable {
public void run() {
synchronized (num) {
System.out.println("start" + Thread.currentThread().getName());
try {
Thread.sleep(20000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("end" + Thread.currentThread().getName());
}
}
}
class myThreadClass2 implements Runnable {
public void run() {
num++;
System.out.println("start" + Thread.currentThread().getName());
System.out.println("end" + Thread.currentThread().getName());
}
}
}