Lock锁
实例化Reentrantlock
private Reentrantlock lock = new Reentrantlock( ) ;
public void run( ) {
whilie(true){
try{
lock.lock( );//加锁
try{
需要运行的代码
}finally{
lock.unlock( );//解锁
}
}
}
}
标签:加锁,lock,Reentrantlock,private,try,安全,线程,方法 From: https://www.cnblogs.com/liujy2233/p/16884431.html