关系cmd的
这是我的代码class ticket implements Runnable
{
private int num = 100;
Object obj = new Object();
public void run()
{
while(true)
{
synchronized(obj)
{
if(num>0)
{
try
{
Thread.sleep(5);
}
catch (InterruptedException e){}
System.out.println(Thread.currentThread().getName()+"--------->"+num--);
}
}
}
}
}
class synchronized_safe
{
public static void main(String[] args)
{
ticket t = new ticket();
Thread t1 = new Thread(t);
Thread t2 = new Thread(t);
Thread t3 = new Thread(t);
Thread t4 = new Thread(t);
t1.start();
t2.start();
t3.start();
t4.start();
}
}
每次在cmd上运行这个小类,java synchronized,然后cmd光标就停留在结果后面,前面没有地址了,也不能输入,怎么解决?