ITPub博客

首页 > > > 请问下这和synchronized锁为什么没有起错用呢

请问下这和synchronized锁为什么没有起错用呢

作者:ofan 时间:2019-10-09 16:42:24 0 删除 编辑
public class AccountSync implements Runnable{
static Integer count = 0;
static String str ="111";
@Override
public void run() {
for(int j=0;j<10000000;j++){
synchronized(count){
count++;
}
}
}
// static AccountSync account = new AccountSync();
public static void main(String[] args) throws InterruptedException {
AccountSync account = new AccountSync();
Thread t1 = new Thread(account);
Thread t2 = new Thread(account);
t1.start();
t2.start();
t1.join();
t2.join();
System.out.println(count);

}
}


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4571/viewspace-3149871/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-01

  • 博文量
    159
  • 访问量
    1161