Search in sources :

Example 1 with EagerDtpExecutor

use of com.dtp.core.thread.EagerDtpExecutor in project dynamic-tp by dromara.

the class DtpPostProcessor method postProcessAfterInitialization.

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    if (!(bean instanceof ThreadPoolExecutor)) {
        return bean;
    }
    if (bean instanceof DtpExecutor) {
        DtpExecutor dtpExecutor = (DtpExecutor) bean;
        if (bean instanceof EagerDtpExecutor) {
            ((TaskQueue) dtpExecutor.getQueue()).setExecutor((EagerDtpExecutor) dtpExecutor);
        }
        registerDtp(dtpExecutor);
        return dtpExecutor;
    }
    ApplicationContext applicationContext = ApplicationContextHolder.getInstance();
    DynamicTp dynamicTp;
    try {
        dynamicTp = applicationContext.findAnnotationOnBean(beanName, DynamicTp.class);
        if (dynamicTp == null) {
            return bean;
        }
    } catch (NoSuchBeanDefinitionException e) {
        log.error("There is no bean with the given name {}", beanName, e);
        return bean;
    }
    String poolName = StringUtils.isNotBlank(dynamicTp.value()) ? dynamicTp.value() : beanName;
    registerCommon(poolName, (ThreadPoolExecutor) bean);
    return bean;
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) DtpExecutor(com.dtp.core.thread.DtpExecutor) EagerDtpExecutor(com.dtp.core.thread.EagerDtpExecutor) TaskQueue(com.dtp.core.support.TaskQueue) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) DynamicTp(com.dtp.core.support.DynamicTp) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) EagerDtpExecutor(com.dtp.core.thread.EagerDtpExecutor)

Example 2 with EagerDtpExecutor

use of com.dtp.core.thread.EagerDtpExecutor in project dynamic-tp by dromara.

the class ThreadPoolBuilder method createInternal.

private DtpExecutor createInternal(ThreadPoolBuilder builder) {
    DtpExecutor dtpExecutor;
    if (ioIntensive) {
        TaskQueue taskQueue = new TaskQueue(builder.queueCapacity);
        dtpExecutor = new EagerDtpExecutor(builder.corePoolSize, builder.maximumPoolSize, builder.keepAliveTime, builder.timeUnit, taskQueue, builder.threadFactory, builder.rejectedExecutionHandler);
        taskQueue.setExecutor((EagerDtpExecutor) dtpExecutor);
    } else {
        dtpExecutor = new DtpExecutor(builder.corePoolSize, builder.maximumPoolSize, builder.keepAliveTime, builder.timeUnit, builder.workQueue, builder.threadFactory, builder.rejectedExecutionHandler);
    }
    return dtpExecutor;
}
Also used : DtpExecutor(com.dtp.core.thread.DtpExecutor) EagerDtpExecutor(com.dtp.core.thread.EagerDtpExecutor) EagerDtpExecutor(com.dtp.core.thread.EagerDtpExecutor)

Aggregations

DtpExecutor (com.dtp.core.thread.DtpExecutor)2 EagerDtpExecutor (com.dtp.core.thread.EagerDtpExecutor)2 DynamicTp (com.dtp.core.support.DynamicTp)1 TaskQueue (com.dtp.core.support.TaskQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1 ApplicationContext (org.springframework.context.ApplicationContext)1