import java.util.HashMap;java
import java.util.Map;ide
import java.util.concurrent.locks.LockSupport;this
class Runt implements Runnable{spa
int i=0;對象
public Runt(int i){get
this.i=i;it
}io
@Overrideclass
public void run() {import
// 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){}
}
}