Changeset 1909 for trunk


Ignore:
Timestamp:
2011-06-26 09:30:14 (11 months ago)
Author:
bruno
Message:

Add hack to stop the FilesystemAlterationMonitor?. Otherwise repeated stop/start of KauriRuntime? within one JVM has increasing number of these threads.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/kauri-runtime/src/main/java/org/kauriproject/runtime/KauriRuntime.java

    r1877 r1909  
    1818import java.io.IOException; 
    1919import java.io.InputStream; 
     20import java.lang.reflect.Field; 
    2021import java.net.MalformedURLException; 
    2122import java.util.*; 
     
    4344import org.kauriproject.util.io.IOUtils; 
    4445import org.kauriproject.conf.Conf; 
    45 import org.restlet.Context; 
    46 import org.restlet.engine.component.ChildContext; 
    4746 
    4847/** 
     
    306305 
    307306        // TODO temporarily disabled because FAM.stop() is slow 
    308         // See JCI jira patch: https://issues.apache.org/jira/browse/JCI-57 
     307        // See JCI jira patch: https://issues.apache.org/jira/browse/JCI-57 (the newer one in commons-io has the same problem) 
    309308        // fam.stop(); 
     309        // Added the following workaround: 
     310        if (System.getSecurityManager() == null) { 
     311            try { 
     312                Field famRunningField = fam.getClass().getDeclaredField("running"); 
     313                famRunningField.setAccessible(true); 
     314                Field threadField = fam.getClass().getDeclaredField("thread"); 
     315                threadField.setAccessible(true); 
     316                Thread famThread = (Thread)threadField.get(fam); 
     317                famRunningField.setBoolean(fam, false); 
     318                famThread.interrupt(); 
     319                fam.stop(); 
     320            } catch (Exception e) { 
     321                infolog.error("Error stopping FilesystemAlterationMonitor", e); 
     322            } 
     323        } else { 
     324            infolog.warn("Unable to stop the FilesystemAlterationMonitor using workaround since a security manager is installed."); 
     325        } 
    310326 
    311327        // In case starting the runtime failed, modules might be null 
Note: See TracChangeset for help on using the changeset viewer.