package ThreadExample;
/**
*
* @author Administrator
*/
public class SynThread {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Share s=new Share();
MyThread m1=new MyThread(s,"Thread1");
MyThread m2=new MyThread(s,"Thread2");
MyThread m3=new MyThread(s,"Thread3");
// TODO code application logic here
}
}
class MyThread extends Thread{
Share s;
MyThread(Share s,String str){
super(str);
this.s=s;
start();
}
public void run(){
s.doword(Thread.currentThread().getName());
}
}
class Share{
public synchronized void doword(String str){
for(int i=0;i<5;i++){
System.out.println("Started :"+str);
try{
Thread.sleep(100);
}catch(Exception e){}
}
}
}
/*输出
线程“主”java.lang.VerifyError 中的异常:(类:ThreadExample/Share,方法:签名:()V)构造函数必须在 ThreadExample.SynThread.main(SynThread.java:18) 调用 super() 或 this() */