相关疑难解决方法(0)

Java类中的线程安全性

为什么这个java类不是Thread安全的.

class TestClass {  
   private int x;

   int get() {
       return x;
   }

   void set(int x) {
       this.x = x;
   }  
}
Run Code Online (Sandbox Code Playgroud)

我读到需要关键字synchronized来使其线程安全吗?毕竟不是在原子内完成的操作?

java thread-safety

16
推荐指数
3
解决办法
914
查看次数

标签 统计

java ×1

thread-safety ×1