Re: basic thread issue
From: Lee Fesperman (firstsql_at_ix.netcom.com)
Date: 01/24/04
- Next message: sowbug: "Re: Ant not excluding on javac task"
- Previous message: JScoobyCed: "Re: Are you interested in the code of the Java.Shinwow trojan ?"
- In reply to: Matt Humphrey: "Re: basic thread issue"
- Next in thread: Chris Uppal: "Re: basic thread issue"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 24 Jan 2004 02:48:39 GMT
Matt Humphrey wrote:
>
> "Lee Fesperman" <firstsql@ix.netcom.com> wrote in message
> news:4011884E.5A5C@ix.netcom.com..
> > Matt Humphrey wrote:
> > > ...
> >
> > You are incorrect. Aside from external resources, mutable variables
> > (instance or class, but not local) are the only reason for
> > contention/synchronization between threads. For example,
> > there are no contention problems for immutable objects (String,
> > Integer, ...) because they contain no mutable instance variables.
>
> Thanks for pointing out that contention can occur on class variables. I
> agree that contention can occur whenever more than one thread accesses a
> shared data container (instance or class variable) that can change state.
> However, I cite contention on objects because (other than class variables)
> it can only happen when there is a shared reference and it doesn't matter
> what kinds of variables the references are stored in. I often find that
> people confuse the variable and the object and mistakenly believe that by
> calling the methods of a typical object via a local or final variable means
> the result will be threadsafe. Even calling the methods of an application's
> immutable object (one with no mutable instance variables) can cause
> contention if those variables ultimately refer to objects that are mutable
> and shared.
You shouldn't confuse people further by distorting what's really happening. You said
"Threads have contention for objects, not variables." That is wrong.
I wouldn't call an object that allows you to change the objects it references immutable.
For instance, java.lang.String contains a char array that is both mutable and shared (by
other String objects), however there is no contention because no one can actually change
the contents of the array.
-- Lee Fesperman, FirstSQL, Inc. (http://www.firstsql.com) ============================================================== * The Ultimate DBMS is here! * FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
- Next message: sowbug: "Re: Ant not excluding on javac task"
- Previous message: JScoobyCed: "Re: Are you interested in the code of the Java.Shinwow trojan ?"
- In reply to: Matt Humphrey: "Re: basic thread issue"
- Next in thread: Chris Uppal: "Re: basic thread issue"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|