use of org.apache.tomcat.InstanceManager in project tomcat by apache.
the class JspServletWrapper method getServlet.
public Servlet getServlet() throws ServletException {
// new servlet object is read consistently)
if (reload) {
synchronized (this) {
// of different pages, but not the same page.
if (reload) {
// This is to maintain the original protocol.
destroy();
final Servlet servlet;
try {
InstanceManager instanceManager = InstanceManagerFactory.getInstanceManager(config);
servlet = (Servlet) instanceManager.newInstance(ctxt.getFQCN(), ctxt.getJspLoader());
} catch (Exception e) {
Throwable t = ExceptionUtils.unwrapInvocationTargetException(e);
ExceptionUtils.handleThrowable(t);
throw new JasperException(t);
}
servlet.init(config);
if (!firstTime) {
ctxt.getRuntimeContext().incrementJspReloadCount();
}
theServlet = servlet;
reload = false;
// Volatile 'reload' forces in order write of 'theServlet' and new servlet object
}
}
}
return theServlet;
}
use of org.apache.tomcat.InstanceManager in project tomcat by apache.
the class TestDefaultInstanceManager method testConcurrency.
/*
* Performance test. Comment out @Ignore to run the test.
*/
@Ignore
@Test
public void testConcurrency() throws Exception {
// Create a populated InstanceManager
Tomcat tomcat = getTomcatInstance();
Context ctx = tomcat.addContext(null, "", null);
tomcat.start();
InstanceManager im = ctx.getInstanceManager();
for (int i = 1; i < 9; i++) {
doTestConcurrency(im, i);
}
}
use of org.apache.tomcat.InstanceManager in project tomee by apache.
the class JavaEEDefaultServerEnpointConfigurator method getEndpointInstance.
@Override
public <T> T getEndpointInstance(final Class<T> clazz) throws InstantiationException {
final ClassLoader classLoader = clazz.getClassLoader();
InstanceManager instanceManager = instanceManagers.get(classLoader);
if (instanceManager == null) {
final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
if (tccl != null) {
instanceManager = instanceManagers.get(tccl);
}
}
// if we have a single app fallback otherwise we don't have enough contextual information here
if (instanceManager == null && instanceManagers.size() == 1) {
instanceManager = instanceManagers.values().iterator().next();
}
if (instanceManager == null) {
return super.getEndpointInstance(clazz);
}
try {
return clazz.cast(instanceManager.newInstance(clazz));
} catch (final Exception e) {
if (InstantiationException.class.isInstance(e)) {
throw InstantiationException.class.cast(e);
}
throw new InstantiationException(e.getMessage());
}
}
Aggregations