Search in sources :

Example 6 with DtpExecutor

use of com.dtp.core.thread.DtpExecutor in project austin by ZhongFuCheng3y.

the class ThreadPoolTest method send.

@GetMapping("/tp")
public void send() {
    DtpExecutor dtpExecutor1 = DtpRegistry.getExecutor("austin-im.notice");
    DtpExecutor dtpExecutor2 = DtpRegistry.getExecutor("execute-xxl-thread-pool");
    DtpExecutor dtpExecutor3 = DtpRegistry.getExecutor("dynamic-tp-test-2");
    System.out.println(dtpExecutor1);
    System.out.println(dtpExecutor2);
    System.out.println(dtpExecutor3);
}
Also used : DtpExecutor(com.dtp.core.thread.DtpExecutor) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 7 with DtpExecutor

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

the class RejectedAware method beforeReject.

/**
 * Do sth before reject.
 * @param executor ThreadPoolExecutor instance
 */
default void beforeReject(ThreadPoolExecutor executor) {
    if (executor instanceof DtpExecutor) {
        DtpExecutor dtpExecutor = (DtpExecutor) executor;
        dtpExecutor.incRejectCount(1);
        Runnable runnable = () -> AlarmManager.doAlarm(dtpExecutor, REJECT);
        AlarmManager.triggerAlarm(dtpExecutor.getThreadPoolName(), REJECT.getValue(), runnable);
    }
}
Also used : DtpExecutor(com.dtp.core.thread.DtpExecutor)

Example 8 with DtpExecutor

use of com.dtp.core.thread.DtpExecutor 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 9 with DtpExecutor

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

the class ThreadPoolBuilder method buildDtpExecutor.

/**
 * Build dynamic threadPoolExecutor.
 *
 * @param builder the targeted builder
 * @return the newly created DtpExecutor instance
 */
private DtpExecutor buildDtpExecutor(ThreadPoolBuilder builder) {
    Assert.notNull(builder.threadPoolName, "The thread pool name must not be null.");
    DtpExecutor dtpExecutor = createInternal(builder);
    dtpExecutor.setThreadPoolName(builder.threadPoolName);
    dtpExecutor.allowCoreThreadTimeOut(builder.allowCoreThreadTimeOut);
    dtpExecutor.setWaitForTasksToCompleteOnShutdown(builder.waitForTasksToCompleteOnShutdown);
    dtpExecutor.setAwaitTerminationSeconds(builder.awaitTerminationSeconds);
    dtpExecutor.setPreStartAllCoreThreads(builder.preStartAllCoreThreads);
    dtpExecutor.setRunTimeout(builder.runTimeout);
    dtpExecutor.setQueueTimeout(builder.queueTimeout);
    dtpExecutor.setTaskWrappers(builder.taskWrappers);
    dtpExecutor.setNotifyItems(builder.notifyItems);
    return dtpExecutor;
}
Also used : DtpExecutor(com.dtp.core.thread.DtpExecutor) EagerDtpExecutor(com.dtp.core.thread.EagerDtpExecutor)

Example 10 with DtpExecutor

use of com.dtp.core.thread.DtpExecutor 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)19 EagerDtpExecutor (com.dtp.core.thread.EagerDtpExecutor)3 RuntimeInfo (cn.hutool.system.RuntimeInfo)2 JvmStats (com.dtp.common.dto.JvmStats)2 Metrics (com.dtp.common.dto.Metrics)2 NotifyItem (com.dtp.common.dto.NotifyItem)2 ThreadPoolStats (com.dtp.common.dto.ThreadPoolStats)2 DtpContext (com.dtp.core.context.DtpContext)2 ExecutorWrapper (com.dtp.core.support.ExecutorWrapper)2 lombok.val (lombok.val)2 ReadOperation (org.springframework.boot.actuate.endpoint.annotation.ReadOperation)2 CollUtil (cn.hutool.core.collection.CollUtil)1 DtpProperties (com.dtp.common.config.DtpProperties)1 ThreadPoolProperties (com.dtp.common.config.ThreadPoolProperties)1 NotifyPlatform (com.dtp.common.dto.NotifyPlatform)1 NotifyTypeEnum (com.dtp.common.em.NotifyTypeEnum)1 StreamUtil (com.dtp.common.util.StreamUtil)1 DynamicTp (com.dtp.core.support.DynamicTp)1 TaskQueue (com.dtp.core.support.TaskQueue)1 Lists (com.google.common.collect.Lists)1