sem.readLock();
System.out.println("Read op:"+getName());
try {sleep((int)(Math.random()*50));}
catch(InterruptedException e){;}
System.out.println("Unlocking readLock:"+getName());
sem.readUnlock();
}
else if(op.compareTo("write")==0){
System.out.println("Trying to get writeLock:"+getName());
sem.writeLock();
System.out.println("Write op:"+getName());
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/