use of com.alipay.sofa.common.thread.SofaThreadPoolExecutor in project sofa-boot by sofastack.
the class SpringContextInstallStage method refreshSpringContextParallel.
/**
* start sofa module parallel
*
* @param application
*/
private void refreshSpringContextParallel(ApplicationRuntimeModel application) {
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
List<DeploymentDescriptor> coreRoots = new ArrayList<>();
int coreSize = (int) (CPU_COUNT * sofaModuleProperties.getParallelRefreshCoreCountFactor());
long taskTimeout = sofaModuleProperties.getParallelRefreshTimeout();
long period = sofaModuleProperties.getParallelRefreshCheckPeriod();
ThreadPoolExecutor executor = new SofaThreadPoolExecutor(coreSize, coreSize, 60, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(DEFAULT_REFRESH_TASK_QUEUE_SIZE), new NamedThreadFactory("sofa-module-start"), new ThreadPoolExecutor.CallerRunsPolicy(), "sofa-module-start", SofaBootConstants.SOFABOOT_SPACE_NAME, taskTimeout, period, TimeUnit.SECONDS);
try {
for (DeploymentDescriptor deployment : application.getResolvedDeployments()) {
DependencyTree.Entry entry = application.getDeployRegistry().getEntry(deployment.getModuleName());
if (entry != null && entry.getDependencies() == null) {
coreRoots.add(deployment);
}
}
refreshSpringContextParallel(coreRoots, application.getResolvedDeployments().size(), application, executor);
} finally {
executor.shutdown();
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
use of com.alipay.sofa.common.thread.SofaThreadPoolExecutor in project sofa-boot by sofastack.
the class AsyncTaskExecutor method createThreadPoolExecutor.
/**
* Create thread pool to execute async init task
* @return
*/
private static ThreadPoolExecutor createThreadPoolExecutor(Environment environment) {
int threadPoolCoreSize = CPU_COUNT + 1;
String coreSizeStr = environment.getProperty(SofaBootConstants.ASYNC_INIT_BEAN_CORE_SIZE);
if (coreSizeStr != null) {
threadPoolCoreSize = Integer.parseInt(coreSizeStr);
}
int threadPoolMaxSize = CPU_COUNT + 1;
String maxSizeStr = environment.getProperty(SofaBootConstants.ASYNC_INIT_BEAN_MAX_SIZE);
if (maxSizeStr != null) {
threadPoolMaxSize = Integer.parseInt(maxSizeStr);
}
SofaLogger.info(String.format("create async-init-bean thread pool, corePoolSize: %d, maxPoolSize: %d.", threadPoolCoreSize, threadPoolMaxSize));
return new SofaThreadPoolExecutor(threadPoolCoreSize, threadPoolMaxSize, 30, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new NamedThreadFactory("async-init-bean"), new ThreadPoolExecutor.CallerRunsPolicy(), "async-init-bean", "sofa-boot");
}
use of com.alipay.sofa.common.thread.SofaThreadPoolExecutor in project sofa-boot by alipay.
the class AsyncTaskExecutor method createThreadPoolExecutor.
/**
* Create thread pool to execute async init task
* @return
*/
private static ThreadPoolExecutor createThreadPoolExecutor(Environment environment) {
int threadPoolCoreSize = CPU_COUNT + 1;
String coreSizeStr = environment.getProperty(SofaBootConstants.ASYNC_INIT_BEAN_CORE_SIZE);
if (coreSizeStr != null) {
threadPoolCoreSize = Integer.parseInt(coreSizeStr);
}
int threadPoolMaxSize = CPU_COUNT + 1;
String maxSizeStr = environment.getProperty(SofaBootConstants.ASYNC_INIT_BEAN_MAX_SIZE);
if (maxSizeStr != null) {
threadPoolMaxSize = Integer.parseInt(maxSizeStr);
}
SofaLogger.info(String.format("create async-init-bean thread pool, corePoolSize: %d, maxPoolSize: %d.", threadPoolCoreSize, threadPoolMaxSize));
return new SofaThreadPoolExecutor(threadPoolCoreSize, threadPoolMaxSize, 30, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new NamedThreadFactory("async-init-bean"), new ThreadPoolExecutor.CallerRunsPolicy(), "async-init-bean", "sofa-boot");
}
use of com.alipay.sofa.common.thread.SofaThreadPoolExecutor in project sofa-boot by alipay.
the class SpringContextInstallStage method refreshSpringContextParallel.
/**
* start sofa module parallel
*
* @param application
*/
private void refreshSpringContextParallel(ApplicationRuntimeModel application) {
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
List<DeploymentDescriptor> coreRoots = new ArrayList<>();
int coreSize = (int) (CPU_COUNT * sofaModuleProperties.getParallelRefreshCoreCountFactor());
long taskTimeout = sofaModuleProperties.getParallelRefreshTimeout();
long period = sofaModuleProperties.getParallelRefreshCheckPeriod();
ThreadPoolExecutor executor = new SofaThreadPoolExecutor(coreSize, coreSize, 60, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(DEFAULT_REFRESH_TASK_QUEUE_SIZE), new NamedThreadFactory("sofa-module-start"), new ThreadPoolExecutor.CallerRunsPolicy(), "sofa-module-start", SofaBootConstants.SOFABOOT_SPACE_NAME, taskTimeout, period, TimeUnit.SECONDS);
try {
for (DeploymentDescriptor deployment : application.getResolvedDeployments()) {
DependencyTree.Entry entry = application.getDeployRegistry().getEntry(deployment.getModuleName());
if (entry != null && entry.getDependencies() == null) {
coreRoots.add(deployment);
}
}
refreshSpringContextParallel(coreRoots, application.getResolvedDeployments().size(), application, executor);
} finally {
executor.shutdown();
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
Aggregations