Search in sources :

Example 26 with ThreadPoolProfile

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)));
}
Also used : ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile) Test(org.junit.Test)

Example 27 with ThreadPoolProfile

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);
}
Also used : ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile)

Example 28 with ThreadPoolProfile

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);
}
Also used : ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile)

Example 29 with ThreadPoolProfile

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();
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) SizedScheduledExecutorService(org.apache.camel.util.concurrent.SizedScheduledExecutorService)

Example 30 with ThreadPoolProfile

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);
}
Also used : ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile)

Aggregations

ThreadPoolProfile (org.apache.camel.spi.ThreadPoolProfile)41 ExecutorService (java.util.concurrent.ExecutorService)16 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)11 SizedScheduledExecutorService (org.apache.camel.util.concurrent.SizedScheduledExecutorService)11 CamelContext (org.apache.camel.CamelContext)5 RouteBuilder (org.apache.camel.builder.RouteBuilder)5 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 ExecutorServiceManager (org.apache.camel.spi.ExecutorServiceManager)4 ThreadPoolProfileBuilder (org.apache.camel.builder.ThreadPoolProfileBuilder)3 HashSet (java.util.HashSet)2 Exchange (org.apache.camel.Exchange)2 Processor (org.apache.camel.Processor)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 ThreadPoolRejectedPolicy (org.apache.camel.ThreadPoolRejectedPolicy)1 ThreadPoolProfileDefinition (org.apache.camel.model.ThreadPoolProfileDefinition)1 BodyInAggregatingStrategy (org.apache.camel.processor.BodyInAggregatingStrategy)1 Pipeline (org.apache.camel.processor.Pipeline)1