Re: basic thread issue

From: Lee Fesperman (firstsql_at_ix.netcom.com)
Date: 01/24/04


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)


Relevant Pages

  • Re: basic thread issue
    ... >> Threads have contention for objects, ... > because they contain no mutable instance variables. ... Thanks for pointing out that contention can occur on class variables. ...
    (comp.lang.java.programmer)
  • Re: Okay, Ive had it
    ... the point of contention in our ... exchange was over punctuation in court transcripts. ... disagreed with my choice of legal references. ... English Guide for Court Reporters*, AAERT's study guide, and ...
    (sci.med.transcription)
  • Re: Nice idea UPA
    ... references going over your head. ... who the fuck dosent know where that "contention" came from. ... muthafuckinbitch"......i'll ...
    (rec.sport.disc)