is this acceptor threadsafe?

2011-08-15 Thread 叶茂
 /**
 * Server socket acceptor thread.
 */
protected class Acceptor implements Runnable {
/**
 * The background thread that listens for incoming TCP/IP connections 
and
 * hands them off to an appropriate processor.
 */
public void run() {
// Loop until we receive a shutdown command
while (running) {
// Loop if endpoint is paused
while (paused) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// Ignore
}
}
try {
// Accept the next incoming connection from the server 
socket
SocketChannel socket = serverSock.accept();
if we have more than 1 acceptors,will the statement of serverSock.accept() be 
theadsafe?

 

Re: is this acceptor threadsafe?

2011-08-15 Thread Filip Hanik - Dev Lists

On 8/15/2011 6:34 AM, Ҷï wrote:

  /**
  * Server socket acceptor thread.
  */
 protected class Acceptor implements Runnable {
 /**
  * The background thread that listens for incoming TCP/IP connections 
and
  * hands them off to an appropriate processor.
  */
 public void run() {
 // Loop until we receive a shutdown command
 while (running) {
 // Loop if endpoint is paused
 while (paused) {
 try {
 Thread.sleep(1000);
 } catch (InterruptedException e) {
 // Ignore
 }
 }
 try {
 // Accept the next incoming connection from the server 
socket
 SocketChannel socket = serverSock.accept();
if we have more than 1 acceptors,will the statement of serverSock.accept() be 
theadsafe?

yes, and serverSock.accept will lock, so there is no need for more than one 
acceptor thread, more than one thread will just queue up on the lock






-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org