R9J*_*R9J 7 java multithreading thread-safety
I found that declaring a variable as static makes no sense
在多线程中.我认为,这是因为every thread has its own stack
.这是唯一的原因吗?
我知道static variables should be used within synchronized block
.但为什么?
Jun*_*san 18
静态在多线程中毫无意义.
我担心你正在做出相反的声明.静态变量是一种共享资源,可用于在不同线程之间交换一些信息.我们在访问这样的共享资源时需要小心.因此,我们需要确保在多线程环境中对静态变量的访问是同步的.
每个线程都有自己的堆栈
这是一个正确的陈述.Each thread has its own stack but they share the process heap.
Stack只保存局部变量,而不保存堆上的变量.静态变量存储在PermGen
堆的部分中,因此应该很好地保护对它们的访问.
归档时间: |
|
查看次数: |
14741 次 |
最近记录: |