多线程 synchronized锁定当前对象
2021-07-16 10:07
阅读:982
标签:void read eth nbsp span 对象 锁定 col sys
synchronized(this) 和synchronized一样,都是锁定当前对象。
public class Task { synchronized public void otherMethod(){ System.out.println("--------run otherMethod"); } public void doLongTimeTask(){ synchronized (this){ for (int i=0;i){ System.out.println("synchronized threadName="+Thread.currentThread().getName()+" i="+(i+1)); } } } }
多线程 synchronized锁定当前对象
标签:void read eth nbsp span 对象 锁定 col sys
原文地址:https://www.cnblogs.com/newlangwen/p/9534595.html
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:多线程 synchronized锁定当前对象
文章链接:http://soscw.com/index.php/essay/105971.html
文章标题:多线程 synchronized锁定当前对象
文章链接:http://soscw.com/index.php/essay/105971.html
评论
亲,登录后才可以留言!