在main方法中,有4个LockSupport.unpark方法,当t1线程运行时应该Lock.park()不应该堵塞代码,但是实际是堵塞的为什么,为什么main方法中注释中的方法就可以输出11111,park方法没有阻塞当前进程。
public class LockSupportDemo {
public static Object u = new Object();
static ChangeObjectThread t1 = new ChangeObjectThread("t1");
public static class ChangeObjectThread extends Thread{
public ChangeObjectThread(String name)
{
super.setName(name);
}
@Override
public void run() {
synchronized (u)
{
LockSupport.park(Thread.currentThread());
System.out.println("in "+ getName());
if(Thread.interrupted())
{
System.out.println(getName()+" interrupted");
}
}
System.out.println(getName() +"isOver");
}
}
public static void main(String[] args) throws InterruptedException {
LockSupport.unpark(t1);
LockSupport.unpark(t1);
LockSupport.unpark(t1);
LockSupport.unpark(t1);
LockSupport.unpark(t1);
t1.start();
/**
*LockSupport.unpark(Thread.cuurentThread);
*LockSupport.unpark(Thread.cuurentThread);
*Lock.park();
*System.out.println("11111");
*
*/
}
}
牛魔王的故事
米脂
相关分类