标签: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<10000;i++){ System.out.println("synchronized threadName="+Thread.currentThread().getName()+" i="+(i+1)); } } } }
标签:void read eth nbsp span 对象 锁定 col sys
原文地址:https://www.cnblogs.com/newlangwen/p/9534595.html