私は同期されたステートメントで作業していて、次のプログラムを作成しました...オブジェクト参照としてこれを使用してrunnクラスを同期しました..bt smhw目的の出力はありません....
class runn extends Thread {
String s;
runn(String a) {
s=a;
start();
}
public void show() {
System.out.print("["+s);
try {
sleep(50);
} catch(Exception a){}
System.out.print("]");
}
public void run() {
synchronized(this) {
show();
}
}
}
public class multi4 {
public static void main(String[] args) throws InterruptedException{
new runn("hello ");
new runn("this is ");
new runn("multithreading");
}
}
出力は次のようになります。
[hello][this is][multithreading]
しかし、同期が機能していません
助けてください。