Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with ServerSocket.accept

843790May 28 2006 — edited Apr 12 2007
Hi, I'm from Italy so I apologize for my English.
The problem is this, I created a separated Thread to listen the connections that come from the various clients, when it receive a connection it creates a new Thread to manage the connection.
The problem is that I need to stop the Thread (the one that look for new connetions), whenever I need it, but how can i do it if the method ServerSocket.accept(); stop the execution of the thread.
The listener of new connections extends Thread and this is the run method overridden.
public void run() {
	ServerSocket ss;
	Server myServer; /* Another class that extends Thread to manage the connection */
	while (true) {
		try {
			ss = new ServerSocket(port, queueLength);
			Socket sd = ss.accept();
			myServer = new Server(sd);
			myServer.start();
		}
		catch (IOException e) {
		}
	}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 9 2007
Added on May 28 2006
14 comments
1,100 views