Re: Threads and statics
On Apr 7, 10:38 am, Robert Klemme <shortcut...@googlemail.com> wrote:
On 7 Apr., 14:41, Patricia Shanahan <p...@acm.org> wrote:
On 4/7/2011 5:34 AM, Dirk Bruere at NeoPax wrote:
Is there a problem with multiple threads using the same static method=
of
a class?
The local variables for a method go on the calling thread's stack,
regardless of whether the method is static or not.
Static data presents the same issues when accessed from a static method
as when accessed from non-static methods.
I would word it differently: shared mutable state presents concurrency
issues if not properly synchronized. Whether the data is stored in a
static variable or a member variable (or even a database outside the
JVM) does not really matter for the concurrency implications.
You'd be wording a different "it". The problems go beyond concurrency
issues. They can present in single-threaded code, too.
For example, the dreaded 'java.util.ConcurrentModificationException'
is not limited to multithreaded scenarios.
--
Lew