};
public class SyncDemo02{
public static void main(String args[]){
MyThread mt = new MyThread() ; // 定义线程对象
new Thread(mt).start();
new Thread(mt).start();
new Thread(mt).start();
};
public class ThreadDemo{
public static void main(String args[]){
MyThread mt = new MyThread() ; // 定义线程对象
new Thread(mt).start();
new Thread(mt).start();
new Thread(mt).start();
}
};
/*
synchronized使用的锁只要是对象的索引就可以了,但是要注意锁一定要相同(例如死锁当中就必须持持有锁)。
public void run(){
if(flag){