ThreadPoolProfile threadPool = configure(new ThreadPoolProfile(), $camel.getConfig("threads")); ctx.getExecutorServiceManager().setDefaultThreadPoolProfile(threadPool);
@Override public ExecutorService newThreadPool(ThreadPoolProfile profile, ThreadFactory factory) { return newThreadPool(profile.getPoolSize(), profile.getMaxPoolSize(), profile.getKeepAliveTime(), profile.getTimeUnit(), profile.getMaxQueueSize(), profile.getRejectedExecutionHandler(), factory); }
@Override public ScheduledExecutorService newScheduledThreadPool(ThreadPoolProfile profile, ThreadFactory threadFactory) { RejectedExecutionHandler rejectedExecutionHandler = profile.getRejectedExecutionHandler(); if (rejectedExecutionHandler == null) { rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy(); } ScheduledThreadPoolExecutor answer = new RejectableScheduledThreadPoolExecutor( profile.getPoolSize(), threadFactory, rejectedExecutionHandler) { protected void beforeExecute(Thread t, Runnable r) { super.beforeExecute(t, r); before(); } protected void afterExecute(Runnable r, Throwable t) { super.afterExecute(r, t); after(); } }; // need to wrap the thread pool in a sized to guard against the problem that the // JDK created thread pool has an unbounded queue (see class javadoc), which mean // we could potentially keep adding tasks, and run out of memory. if (profile.getMaxPoolSize() > 0) { return new SizedScheduledExecutorService(answer, profile.getMaxQueueSize()); } else { return answer; } }
@Override public ScheduledExecutorService newScheduledThreadPool(ThreadPoolProfile profile, ThreadFactory threadFactory) { return new InstrumentedScheduledExecutorService(threadPoolFactory.newScheduledThreadPool(profile, threadFactory), metricRegistry, profile.getId()); }
@Override public void beforeApplicationStart(CamelContext camelContext) { // error handler LoggingErrorHandlerBuilder handlerBuilder = new LoggingErrorHandlerBuilder(); handlerBuilder.logName("org.openhubframework.openhub.core"); camelContext.setErrorHandlerBuilder(handlerBuilder); camelContext.setHandleFault(true); if (camelContext instanceof DefaultCamelContext){ ((SpringCamelContext) camelContext).setRegistry(registry); } // default thread profile (see DefaultExecutorServiceManager for defaults) ThreadPoolProfile threadPoolProfile = camelContext.getExecutorServiceManager() .getDefaultThreadPoolProfile(); threadPoolProfile.setId(DEFAULT_THREAD_PROFILE); threadPoolProfile.setMaxPoolSize(MAX_THREAD_POOL_SIZE); }
private static void initThreadPoolProfiles(ApplicationContext applicationContext, CamelContext camelContext) { Set<String> defaultIds = new HashSet<>(); // lookup and use custom profiles from the registry Map<String, ThreadPoolProfile> profiles = applicationContext.getBeansOfType(ThreadPoolProfile.class); if (profiles != null && !profiles.isEmpty()) { for (Map.Entry<String, ThreadPoolProfile> entry : profiles.entrySet()) { ThreadPoolProfile profile = entry.getValue(); // do not add if already added, for instance a tracer that is also an InterceptStrategy class if (profile.isDefaultProfile()) { LOG.info("Using custom default ThreadPoolProfile with id: {} and implementation: {}", entry.getKey(), profile); camelContext.getExecutorServiceManager().setDefaultThreadPoolProfile(profile); defaultIds.add(entry.getKey()); } else { camelContext.getExecutorServiceManager().registerThreadPoolProfile(profile); } } } // validate at most one is defined if (defaultIds.size() > 1) { throw new IllegalArgumentException("Only exactly one default ThreadPoolProfile is allowed, was " + defaultIds.size() + " ids: " + defaultIds); } }
@Override public ExecutorService newThreadPool(ThreadPoolProfile profile, ThreadFactory factory) { return newThreadPool(profile.getPoolSize(), profile.getMaxPoolSize(), profile.getKeepAliveTime(), profile.getTimeUnit(), profile.getMaxQueueSize(), profile.getRejectedExecutionHandler(), factory); }
@Override public ScheduledExecutorService newScheduledThreadPool(ThreadPoolProfile profile, ThreadFactory threadFactory) { RejectedExecutionHandler rejectedExecutionHandler = profile.getRejectedExecutionHandler(); if (rejectedExecutionHandler == null) { rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy(); } ScheduledThreadPoolExecutor answer = new RejectableScheduledThreadPoolExecutor( profile.getPoolSize(), threadFactory, rejectedExecutionHandler) { protected void beforeExecute(Thread t, Runnable r) { super.beforeExecute(t, r); before(); } protected void afterExecute(Runnable r, Throwable t) { super.afterExecute(r, t); after(); } }; // need to wrap the thread pool in a sized to guard against the problem that the // JDK created thread pool has an unbounded queue (see class javadoc), which mean // we could potentially keep adding tasks, and run out of memory. if (profile.getMaxPoolSize() > 0) { return new SizedScheduledExecutorService(answer, profile.getMaxQueueSize()); } else { return answer; } }
@Override public ExecutorService newThreadPool(ThreadPoolProfile profile, ThreadFactory threadFactory) { return new InstrumentedExecutorService(threadPoolFactory.newThreadPool(profile, threadFactory), metricRegistry, profile.getId()); }
@Override public ExecutorService newThreadPool(ThreadPoolProfile profile, ThreadFactory threadFactory) { ExecutorService executorService = threadPoolFactory.newThreadPool(profile, threadFactory); return ExecutorServiceMetrics.monitor(meterRegistry, executorService, name(profile.getId())); }
ThreadPoolProfile threadPool = configure(new ThreadPoolProfile(), $camel.getConfig("threads")); ctx.getExecutorServiceManager().setDefaultThreadPoolProfile(threadPool);
@Override public ScheduledExecutorService newScheduledThreadPool(ThreadPoolProfile profile, ThreadFactory threadFactory) { ScheduledExecutorService executorService = threadPoolFactory.newScheduledThreadPool(profile, threadFactory); String executorServiceName = name(profile.getId()); return new TimedScheduledExecutorService(meterRegistry, executorService, executorServiceName, Tags.empty()); }