import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.LockSupport;
class Runt implements Runnable{
int i=0;
public Runt(int i){
this.i=i;
}
@Override
public void run() {
// TODO Auto-generated method stub
synchronized (this) {
LockSupport.park();
System.out.println(Thread.holdsLock(this));//true 返回次对象是否持有锁
System.out.println("i is:"+i);
}
}
}
class ParkULock {
public static void main(String args[]) throws Exception {
//先调用下unpark
// LockSupport.unpark(Thread.currentThread());
Map<Integer,Thread> map = new HashMap<Integer,Thread>();
for (int i=0;i < 10;i++){
Thread t1= new Thread(new Runt(i));
t1.start();
map.put(i, t1);
}
LockSupport.unpark(map.get(2));
while(true){}
}
}