您的位置:首页 > 其它

静态同步方法-同步锁为:类名.class

2016-01-02 00:00 183 查看
摘要: 静态同步方法-同步锁为:类名.class

package com.homework;
public class MyRunnable3 implements Runnable{
public static int sum = 0;
public boolean flag = true;
public Object obj = new Object();
@Override
public void run() {
for(int i=0;i<3;i++){
setSum();
}
}
public static  synchronized void setSum(){//静态同步方法。---同步锁为MyRunnable3.class
sum+=100;
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out
.println(Thread.currentThread().getName() + "存了100元,现有" + sum+":同步方法");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: