D
Dirk Bruere at NeoPax
Is there a problem with multiple threads using the same static method of
a class?
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.
Is there a problem with multiple threads using the same static method of
a class?
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.
Is there a problem with multiple threads using the same static method of
a class?
Eric Sosman said:manipulates). Make sure the data is always seen in a consistent
state, except perhaps by the *one* thread that's in the act of
changing it; then you'll have a correct program.
I have little knowledge about multithreading, but from this
it seems that one can avoid deadlocks as long as one can
avoid situations where more than one resource needs to be
obtained for exclusive access at the same time.
For example,
a program was written by experts in multithreading and then
showed a deadlock the first time after several years of use.
Daniele Futtorovic said:That's a tautology. But there *are* cases where you need exclusive
access to more than one resource at the same time.
The very fact that multi-threaded programs exists proves one
can avoid deadlocks in such cases -- no need to look any
further.
Inventing freely without knowledge, I would first try to pack
such resources into a single »meta resource«, which then can
be obtained or released by a single atomic action, again.
Then, the existence of erroneous programs would prove what?
For the meaning of the verb »prove« in software engineering,
see for example this report:
http://machineslikeus.com/news/building-safety-nets-critical-systems
.
Eric Sosman said:manipulates). Make sure the data is always seen in a consistent
state, except perhaps by the *one* thread that's in the act of
changing it; then you'll have a correct program.
It still could have potential deadlocks. [...]
Eric Sosman said:Eric Sosman said:manipulates). Make sure the data is always seen in a consistent
state, except perhaps by the *one* thread that's in the act of
changing it; then you'll have a correct program.
It still could have potential deadlocks. [...]
I also wrote, in the part you snipped
Deadlock is merely a performance problem. A really, Really,
REALLY bad performance problem.![]()
Eric Sosman said:manipulates). Make sure the data is always seen in a consistent
state, except perhaps by the *one* thread that's in the act of
changing it; then you'll have a correct program.
It still could have potential deadlocks. [...]
I also wrote, in the part you snipped
(It might not be
the fastest possible program -- that's where the hard parts come
in -- but at least it won't have race conditions.)
Deadlock is merely a performance problem. A really, Really,
REALLY bad performance problem.![]()
There's a reason it's not call slightlyilllock.
It's only a fleshwoundlock!
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.