Ant*_*wan 34 java multithreading synchronized
Java中同步方法和同步块的主要思想是什么?
我们为什么要使用它们?
示例代码会很好.我已经阅读了有关同步方法的Java文档,但我没有理解.
这是Java文档代码
public class SynchronizedCounter {
private int c = 0;
public synchronized void increment() {
c++;
}
public synchronized void decrement() {
c--;
}
public synchronized int value() {
return c;
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
68011 次 |
最近记录: |