tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Filip Hanik - Dev Lists <devli...@hanik.com>
Subject Re: is this acceptor threadsafe?
Date Mon, 15 Aug 2011 14:58:42 GMT
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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message