use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class XmlThreadPoolProfileTest method verifyThreadProfile.
@Test
public void verifyThreadProfile(CamelContext context) {
ThreadPoolProfile profile = context.getExecutorServiceManager().getThreadPoolProfile("thread-pool-profile");
assertThat("Thread pool profile is null!", profile, is(notNullValue()));
assertThat("Thread pool profile is incorrect!", profile.getPoolSize(), is(equalTo(5)));
}
use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class DefaultExecutorServiceManager method newFixedThreadPool.
@Override
public ExecutorService newFixedThreadPool(Object source, String name, int poolSize) {
ThreadPoolProfile profile = new ThreadPoolProfile(name);
profile.setPoolSize(poolSize);
profile.setMaxPoolSize(poolSize);
profile.setKeepAliveTime(0L);
return newThreadPool(source, name, profile);
}
use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class DefaultExecutorServiceManager method newScheduledThreadPool.
@Override
public ScheduledExecutorService newScheduledThreadPool(Object source, String name, int poolSize) {
ThreadPoolProfile profile = new ThreadPoolProfile(name);
profile.setPoolSize(poolSize);
return newScheduledThreadPool(source, name, profile);
}
use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class DefaultExecutorServiceManager method doShutdown.
@Override
protected void doShutdown() throws Exception {
// shutdown all remainder executor services by looping and doing this aggressively
// as by normal all threads pool should have been shutdown using proper lifecycle
// by their EIPs, components etc. This is acting as a fail-safe during shutdown
// of CamelContext itself.
Set<ExecutorService> forced = new LinkedHashSet<>();
if (!executorServices.isEmpty()) {
// at first give a bit of time to shutdown nicely as the thread pool is most likely in the process of being shutdown also
LOG.debug("Giving time for {} ExecutorService's to shutdown properly (acting as fail-safe)", executorServices.size());
for (ExecutorService executorService : executorServices) {
try {
boolean warned = doShutdown(executorService, getShutdownAwaitTermination(), true);
// remember the thread pools that was forced to shutdown (eg warned)
if (warned) {
forced.add(executorService);
}
} catch (Throwable e) {
// only log if something goes wrong as we want to shutdown them all
LOG.warn("Error occurred during shutdown of ExecutorService: " + executorService + ". This exception will be ignored.", e);
}
}
}
// log the thread pools which was forced to shutdown so it may help the user to identify a problem of his
if (!forced.isEmpty()) {
LOG.warn("Forced shutdown of {} ExecutorService's which has not been shutdown properly (acting as fail-safe)", forced.size());
for (ExecutorService executorService : forced) {
LOG.warn(" forced -> {}", executorService);
}
}
forced.clear();
// clear list
executorServices.clear();
// do not clear the default profile as we could potential be restarted
Iterator<ThreadPoolProfile> it = threadPoolProfiles.values().iterator();
while (it.hasNext()) {
ThreadPoolProfile profile = it.next();
if (!profile.isDefaultProfile()) {
it.remove();
}
}
}
use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class DefaultExecutorServiceManager method newThreadPool.
@Override
public ExecutorService newThreadPool(Object source, String name, int poolSize, int maxPoolSize) {
ThreadPoolProfile profile = new ThreadPoolProfile(name);
profile.setPoolSize(poolSize);
profile.setMaxPoolSize(maxPoolSize);
return newThreadPool(source, name, profile);
}
Aggregations