Search in sources :

Example 1 with DefaultExecutorFactory

use of com.ctrip.xpipe.concurrent.DefaultExecutorFactory in project x-pipe by ctripcorp.

the class AbstractSpringConfigContext method getGlobalExecutor.

@Bean(name = GLOBAL_EXECUTOR)
public ExecutorService getGlobalExecutor() {
    int corePoolSize = OsUtils.getMultiCpuOrMax(GLOBAL_THREAD_MULTI_CORE, GLOBAL_THREAD_MAX);
    int maxPoolSize = 2 * OsUtils.getCpuCount();
    DefaultExecutorFactory executorFactory = new DefaultExecutorFactory(GLOBAL_EXECUTOR, corePoolSize, maxPoolSize, new ThreadPoolExecutor.AbortPolicy());
    return executorFactory.createExecutorService();
}
Also used : DefaultExecutorFactory(com.ctrip.xpipe.concurrent.DefaultExecutorFactory) Bean(org.springframework.context.annotation.Bean)

Example 2 with DefaultExecutorFactory

use of com.ctrip.xpipe.concurrent.DefaultExecutorFactory in project x-pipe by ctripcorp.

the class DefaultRedisSessionManager method postConstruct.

@PostConstruct
public void postConstruct() {
    int corePoolSize = 30 * OsUtils.getCpuCount();
    int maxPoolSize = 512;
    DefaultExecutorFactory executorFactory = new DefaultExecutorFactory("RedisSession", corePoolSize, maxPoolSize, new ThreadPoolExecutor.AbortPolicy());
    executors = executorFactory.createExecutorService();
    int fixedPoolSize = OsUtils.getCpuCount();
    pingAndDelayExecutor = new DefaultExecutorFactory("Ping-Delay-Executor", fixedPoolSize, fixedPoolSize, new ThreadPoolExecutor.CallerRunsPolicy()).createExecutorService();
    scheduled.scheduleAtFixedRate(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            try {
                removeUnusedRedises();
            } catch (Exception e) {
                logger.error("[removeUnusedRedises]", e);
            }
            for (RedisSession redisSession : sessions.values()) {
                try {
                    redisSession.check();
                } catch (Exception e) {
                    logger.error("[check]" + redisSession, e);
                }
            }
        }
    }, 5, 5, TimeUnit.SECONDS);
}
Also used : AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) DefaultExecutorFactory(com.ctrip.xpipe.concurrent.DefaultExecutorFactory) PostConstruct(javax.annotation.PostConstruct)

Aggregations

DefaultExecutorFactory (com.ctrip.xpipe.concurrent.DefaultExecutorFactory)2 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)1 PostConstruct (javax.annotation.PostConstruct)1 Bean (org.springframework.context.annotation.Bean)1