View | Details | Raw Unified | Return to bug 46264
Collapse All | Expand All

(-)../../apache-tomcat-6.0.18-src-stock/java/org/apache/catalina/startup/HostConfig.java (-13 / +72 lines)
Lines 25-32 Link Here
25
import java.io.IOException;
25
import java.io.IOException;
26
import java.io.InputStream;
26
import java.io.InputStream;
27
import java.util.ArrayList;
27
import java.util.ArrayList;
28
import java.util.EmptyStackException;
29
import java.util.Enumeration;
28
import java.util.HashMap;
30
import java.util.HashMap;
29
import java.util.LinkedHashMap;
31
import java.util.LinkedHashMap;
32
import java.util.Stack;
33
import java.util.Vector;
30
import java.util.jar.JarEntry;
34
import java.util.jar.JarEntry;
31
import java.util.jar.JarFile;
35
import java.util.jar.JarFile;
32
36
Lines 1179-1204 Link Here
1179
     * Undeploy all deployed applications.
1183
     * Undeploy all deployed applications.
1180
     */
1184
     */
1181
    protected void undeployApps() {
1185
    protected void undeployApps() {
1182
1186
1183
        if (log.isDebugEnabled())
1187
        if (log.isDebugEnabled())
1184
            log.debug(sm.getString("hostConfig.undeploying"));
1188
            log.debug(sm.getString("hostConfig.undeploying"));
1185
1189
1186
        // Soft undeploy all contexts we have deployed
1190
        // Soft undeploy all contexts we have deployed
1187
        DeployedApplication[] apps = 
1191
        DeployedApplication[] apps =  (DeployedApplication[]) deployed.values().toArray(new DeployedApplication[0]);
1188
            (DeployedApplication[]) deployed.values().toArray(new DeployedApplication[0]);
1189
        for (int i = 0; i < apps.length; i++) {
1190
            try {
1191
                host.removeChild(host.findChild(apps[i].name));
1192
            } catch (Throwable t) {
1193
                log.warn(sm.getString
1194
                        ("hostConfig.context.remove", apps[i].name), t);
1195
            }
1196
        }
1197
        
1198
        deployed.clear();
1199
1192
1193
               //Number of processors affects the number of shutdown worker threads we should spawn
1194
               //We spawn 2x# Processors to cover threads getting blocked on IO, Network or internal locking
1195
               int numWorkers = Runtime.getRuntime().availableProcessors()*2;
1196
1197
               //Generate a stack for the work.  Stacks are synchronized, so we can use the same stack for multiple threads
1198
               Stack deployedApplicationStack = new Stack();
1199
               for (int i = 0; i < apps.length; i++) {
1200
                       deployedApplicationStack.addElement(apps[i]);
1201
               }
1202
1203
               //Create the workers and start them
1204
               Vector workerThreads = new Vector(numWorkers);
1205
               for (int i = 0; i < numWorkers; i++) {
1206
                       UndeployApplicationWorkerThread uawt = new UndeployApplicationWorkerThread(sm, host, deployedApplicationStack);
1207
                       uawt.start();
1208
                       workerThreads.addElement(uawt);
1209
               }
1210
1211
               //Wait for all threads to finish
1212
               for (Enumeration e  = workerThreads.elements() ; e.hasMoreElements(); ) {
1213
                       UndeployApplicationWorkerThread uawt = (UndeployApplicationWorkerThread) e.nextElement();
1214
                       try {
1215
                               uawt.join();
1216
                       } catch (InterruptedException ie) {
1217
                               //We're probably getting forcefully killed, so we'll give up waiting on the other threads
1218
                               log.warn(sm.getString
1219
                                                ("hostConfig.context.remove", "Global Wait"), ie);
1220
                       }
1221
               }
1222
1223
        deployed.clear();
1200
    }
1224
    }
1201
1225
1226
       /** This inner Thread takes a vector of DeployedApplications.  It will iterate through the vector
1227
        * undeploying each
1228
        */
1229
       class UndeployApplicationWorkerThread extends Thread {
1230
               private StringManager sm;
1231
               private Host host;
1232
               private Stack deployedApplicationStack;
1233
1234
               /** 
1235
                * @param sm The String Manager
1236
                * @param host The Host to undeploy from
1237
                * @param deployedApplicationStack The DeployedApplications to undeploy
1238
                */
1239
               public UndeployApplicationWorkerThread(StringManager sm, Host host, Stack deployedApplicationStack) {
1240
                       this.host=host;
1241
                       this.sm=sm;
1242
                       this.deployedApplicationStack=deployedApplicationStack;
1243
               }
1244
1245
               public void run() {
1246
                       try {
1247
                               while (true) {
1248
                                       DeployedApplication da = (DeployedApplication) deployedApplicationStack.pop();
1249
                                       try {
1250
                                               host.removeChild(host.findChild(da.name));
1251
                                       } catch (Throwable t) {
1252
                                               log.warn(sm.getString
1253
                                                                ("hostConfig.context.remove", da.name), t);
1254
                                       }
1255
                               }
1256
                       } catch (EmptyStackException ese) {
1257
                               //There is no more work to be done. So this is fine, we'll terminate now
1258
                       }
1259
               }
1260
       }
1202
1261
1203
    /**
1262
    /**
1204
     * Check status of all webapps.
1263
     * Check status of all webapps.

Return to bug 46264