Re: basic thread issue
From: Matt Humphrey (matth_at_ivizNOSPAM.com)
Date: 01/23/04
- Next message: Joe: "Re: choices regarding where to place code - in the database or middle tier"
- Previous message: Joe: "Re: choices regarding where to place code - in the database or middle tier"
- In reply to: jim: "basic thread issue"
- Next in thread: Lee Fesperman: "Re: basic thread issue"
- Reply: Lee Fesperman: "Re: basic thread issue"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 23 Jan 2004 12:24:08 -0500
"jim" <jxie@admin.fsu.edu> wrote in message
news:burjl4$ki6$1@news.fsu.edu...
> Do threads make contention to method varaibles? I remember threads can
make
> contention to instance variables. In order to protect instance variable
> integrity, I can use synchronized as a method modifier or use synchronized
> block inside method body. For a method, each thread has a different
> allocated memory space. Is this right?
Threads have contention for objects, not variables. It doesn't matter if
the object is accessed via its reference in an instance variable or a local
variable. If the object can be accessed from more than one thread, there
can be synchronization problems.
Having said that, local variables themselves are not shared across threads.
The value (primitive or object reference) that one thread sees for a local
variable has nothing to do with what a different thread sees. Whether two
variables refer to the same object or not is up to you. Each thread can see
a potentially different value for every local variable. As for objects, if
you have an object that can be accessed by only one thread at a time (by
whatever means possible), you will not have synchronization problems. The
difficulty, of course, is ensuring or proving that more than one thread
cannot or will not access the object at the same time. In that sense,
referencing an object from a local variable does not prevent contention in
the least.
Cheers,
Matt Humphrey
- Next message: Joe: "Re: choices regarding where to place code - in the database or middle tier"
- Previous message: Joe: "Re: choices regarding where to place code - in the database or middle tier"
- In reply to: jim: "basic thread issue"
- Next in thread: Lee Fesperman: "Re: basic thread issue"
- Reply: Lee Fesperman: "Re: basic thread issue"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|