Pages

Monday, July 2, 2012

Axis2 too many open file handle or low disc space

one of our project team using webservices using Axis2 in their project discovered that, Axis is creating lot of temp files in temp folder and that was casuing to too many file handles open and out of disc space problems.
This has caused because of Axis2 was creating modules jars files on every request initiated by the client code. this is an unavoidable situation because Axis2 classloader requires these files.
after investigate how this files are created we got a solution to cache its instance of context for all client request so that Axis2 will not crete module files for each request. here is the sample before and after
old--
insidemethod {

AxisConfigurator configurator = null;
        configurator = new URLBasedAxisConfigurator(new URL(resourceXml), new URL(resourceRepo));
        ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContext(configurator);
        ...
        ...
        }
new--

private static ConfigurationContext configurationContext = null;

insidemethod {

ConfigurationContext ctx = getAxis2ConfigurationContext();
....
....
}
private static synchronized ConfigurationContext getAxis2ConfigurationContext() throws Exception {
if (configurationContext == null) {
    AxisConfigurator configurator = null;
    configurator = new URLBasedAxisConfigurator(new URL(resourceXml), new URL(resourceRepo));
    configurationContext = ConfigurationContextFactory.createConfigurationContext(configurator);
}
return configurationContext;
}