[242] in java-interest
Re: Do threads share data? (eg. NetworkServer)
daemon@ATHENA.MIT.EDU (Jeff Kesselman)
Thu Jun 8 16:34:56 1995
From: jeffpk@netcom.com (Jeff Kesselman)
To: kac@mh1.lbl.gov (Kevin Campbell)
Date: Thu, 8 Jun 1995 13:22:37 -0700 (PDT)
Cc: java-interest@java.sun.com
In-Reply-To: <Pine.SUN.3.91.950607184219.335H-100000@al-thor.lbl.gov> from "Kevin Campbell" at Jun 7, 95 07:17:17 pm
>
> Hi,
> 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.
> I have been unable to find any documentation on this, but I haven't
> read everything yet, so I would be happy to hear of somewhere I can read
> about it.
This is from my experience with other full OOPLs. I havent played much
with Java yet BUT....
Typicly a full OOPL (as opposed to bastardized one like C++) inforces
absolute data hiding between object instances. Each insatcne has its own
copies of all instance data. There are two typical ways to communicate:
A) Class Data:
Some languages (like C++ and, i believe Java) allow a CLASS
to have its own data members which are accessible by all class
instances.
B) Server Objects. If you need access to some generally useful
table of data (like for example a SIN table), you can encapsulate
that data in a single instance of a special-purpose class.
All other objects can then talk to it to get/set data.
In either case you will want to use Java's locking features to prevent
race conditions.
Jeff Kesselman
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com