/**
* @author root
*
*/
public class ThreadMain {
private String name = "Zhongwm";
public void doSomeThing() {
try {
/*synchronized (name) {*/
MyThread mt = (MyThread) Thread.currentThread();
if (mt.getC() == 1) {
mt.sleep(100L);
System.out.println("Hello " + name);
name = "Cheny";
} else {
mt.sleep(3000L);
System.out.println("Hello " + name);
}
/*}*/
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
/**
* @param args
*/
public static void main(String[] args) {
ThreadMain main = new ThreadMain();
MyThread mt1 = new MyThread(main, 1);
MyThread mt2 = new MyThread(main, 2);
mt2.start();
mt1.start();
}
}
class MyThread extends Thread {
private int c=0;
private ThreadMain main=null;
public MyThread() {
}
public MyThread(ThreadMain main,int c) {
this.main=main;
this.c=c;
}
public int getC() {
return c;
}
public void run() {
main.doSomeThing();
}
}