2

synchronized 加锁失败

 3 years ago
source link: https://www.oschina.net/question/2883519_2323807
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

synchronized 加锁失败

如梦之猿 发布于 昨天 10:37
阅读 105
//Controller.class
public static final Object lock = new Object();

String taskNo;
synchronized (lock) {
    taskNo = this.taskOrderManager.getTask(loginUser, getTask);
}
//TaskOrderManager.class
public String getTask(LoginUser loginUser, GetTask getTask)

在Controller层调用的时候加锁未生效,在实际调用的时候还是会有多个线程获取到相同的数据。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK