?? synch1.java
字號:
class Callme
{
synchronized void call(String msg)
{
System.out.println("["+msg);
try
{
Thread.sleep(10000);
}
catch(InterruptedException e)
{
System.out.print("Interrupted");
}
System.out.print("]");
}
}
class Caller implements Runnable
{
String msg;
Callme target;
Thread t;
public Caller(Callme targ,String s)
{
target=targ;
msg=s;
t=new Thread(this);
t.start();
}
public void run()
{
target.call(msg);
}
}
public class Synch1
{
public static void main(String args[])
{
Callme target=new Callme();
Caller ob1=new Caller(target,"hello");
Caller ob2=new Caller(target,"Synchronized");
Caller ob3=new Caller(target,"World");
try
{
ob1.t.join();
ob2.t.join();
ob3.t.join();
}
catch(InterruptedException e)
{
System.out.println("Interrupted");
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -