hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r515269 - /jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
Date Tue, 06 Mar 2007 19:40:49 GMT
Author: olegk
Date: Tue Mar  6 11:40:48 2007
New Revision: 515269

URL: http://svn.apache.org/viewvc?view=rev&rev=515269
Log:
HTTPCORE-54: Fixed NPE in AbstractMultiworkerIOReactor#stopWorkers(). AbstractMultiworkerIOReactor
can now be shut down even if partially initialized

Modified:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java?view=diff&rev=515269&r1=515268&r2=515269
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
Tue Mar  6 11:40:48 2007
@@ -45,6 +45,8 @@
     private final BaseIOReactor[] ioReactors;
     private final Worker[] workers;
     private final Thread[] threads;
+
+    private volatile boolean shutdown;
     
     private int currentWorker = 0;
     
@@ -77,18 +79,31 @@
             this.threads[i] = this.threadFactory.newThread(this.workers[i]);
         }
         for (int i = 0; i < this.workerCount; i++) {
+            if (this.shutdown) {
+                return;
+            }
             this.threads[i].start();
         }
     }
 
     protected void stopWorkers(int millis) 
             throws InterruptedIOException, IOReactorException {
+        if (this.shutdown) {
+            return;
+        }
+        this.shutdown = true;
         for (int i = 0; i < this.workerCount; i++) {
-            this.ioReactors[i].shutdown();
+            BaseIOReactor reactor = this.ioReactors[i];
+            if (reactor != null) {
+                reactor.shutdown();
+            }
         }
         for (int i = 0; i < this.workerCount; i++) {
             try {
-                this.threads[i].join(millis);
+                Thread t = this.threads[i];
+                if (t != null) {
+                    t.join(millis);
+                }
             } catch (InterruptedException ex) {
                 throw new InterruptedIOException(ex.getMessage());
             }
@@ -97,6 +112,9 @@
     
     protected void verifyWorkers() 
             throws InterruptedIOException, IOReactorException {
+        if (this.shutdown) {
+            return;
+        }
         for (int i = 0; i < this.workerCount; i++) {
             Worker worker = this.workers[i];
             Thread thread = this.threads[i];
@@ -160,8 +178,10 @@
 
     static class DefaultThreadFactory implements ThreadFactory {
 
+        private static int COUNT = 0;
+        
         public Thread newThread(final Runnable r) {
-            return new Thread(r, "I/O reactor worker thread");
+            return new Thread(r, "I/O reactor worker thread " + (++COUNT));
         }
         
     }



Mime
View raw message