[233] in java-interest

home help back first fref pref prev next nref lref last post

Re: Do threads share data? (eg. NetworkServer)

daemon@ATHENA.MIT.EDU (jim frost)
Thu Jun 8 09:30:21 1995

To: Kevin Campbell <kac@mh1.lbl.gov>
Cc: java-interest@java.sun.com
In-Reply-To: Your message of "Wed, 07 Jun 1995 19:17:17 EDT."
             <Pine.SUN.3.91.950607184219.335H-100000@al-thor.lbl.gov> 
Date: Thu, 08 Jun 1995 09:23:33 -0400
From: jim frost <jimf@world.std.com>

|  I'm trying to extend the NetworkServer class to be the server for a 
|distributed game (ok, it's tic-tac-toe for now).  The problem I am having 
|is that each time a client connects to the server a new server thread is 
|spawned off, and I don't understand how they are supposed to communicate 
|with each other.  My understanding of threads is that they share the same 
|data space, but the data members of my object don't seem to be shared.

They do share the same data space.  Your example uses an object-local
data member and I believe each thread that gets started refers to its
own object instance so what you really want is to make the counter
variable static (ie shared between all objects).

Also note that you'll want mutual exclusion around the member access.

jim frost
jimf@world.std.com
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post