[227] in java-interest
Do threads share data? (eg. NetworkServer)
daemon@ATHENA.MIT.EDU (Kevin Campbell)
Wed Jun 7 22:28:50 1995
Date: Wed, 7 Jun 1995 19:17:17 -0700 (PDT)
From: Kevin Campbell <kac@mh1.lbl.gov>
To: java-interest@java.sun.com
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.
I have included my very short extension to NetworkServer below. What I
would like to have happen is that every time a new connection is
established, the server prints out a message saying how many clients have
connected so far. For my application I need to have state that is
accessible from all server threads. I remember reading about conditions
and locks in the White Paper, so there must be a way to do this.
Thanks in advance,
Kevin
----------
import net.NetworkServer;
public class TTTServer extends NetworkServer {
int reqnum = 0;
public static void main(String argv[]) {
new TTTServer().startServer(8889);
}
public void serviceRequest() {
System.out.print("Servicing request #" + reqnum++ + "\n");
}
}
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com