码迷,mamicode.com
首页 > 其他好文 > 详细

blocking

时间:2018-08-11 18:54:13      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:oid   ESS   ble   getname   block   thread   ati   world   run   

package blockingtest;

/**
* Hello world!
*/
public class Sync implements Runnable {
int n;

public static void main(String[] args) {
Sync sync = new Sync();
new Thread(sync, "Sync1").start();
new Thread(sync, "Sync2").start();
new Thread(sync, "Sync3").start();
}

public void run() {
for (int i = 0; i < 3; i++) {
inc();
}
}

public synchronized void inc() {
n++;
System.out.print(Thread.currentThread().getName() + "\n");
try {
Thread.sleep(10000);
} catch (Exception ex) {
System.out.print(ex.getMessage());
}

}
}

blocking

标签:oid   ESS   ble   getname   block   thread   ati   world   run   

原文地址:https://www.cnblogs.com/WCFGROUP/p/9460602.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!