Java中的同步??示例程序
前面说到了Java中的同步问题。下面通过一个小小的实例程序来演示Java中的同步方法。其中对前文提到的Counter类做了稍微的修改。 public class Counter { private int c = 0; public void increment() { System.out.println("before increment, c = " + c); c++; try { Thread.sleep(5); } catch (InterruptedException e) { e.printStackTrace();
下载地址
用户评论