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){}
}
}
}
/*出力
スレッド"main"の例外java.lang.VerifyError:(class:ThreadExample / Share、method:signature:()V)コンストラクターはThreadExample.SynThread.main(SynThread.java:18)でsuper()またはthis()を呼び出す必要があります* /