本文整理汇总了Java中org.glassfish.grizzly.threadpool.ThreadPoolConfig.setCorePoolSize方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadPoolConfig.setCorePoolSize方法的具体用法?Java ThreadPoolConfig.setCorePoolSize怎么用?Java ThreadPoolConfig.setCorePoolSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.glassfish.grizzly.threadpool.ThreadPoolConfig
的用法示例。
在下文中一共展示了ThreadPoolConfig.setCorePoolSize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: adjustThreadPool
import org.glassfish.grizzly.threadpool.ThreadPoolConfig; //导入方法依赖的package包/类
private ThreadPoolConfig adjustThreadPool() {
Integer corePoolSize = 2;
Integer maxPoolSize = 8;
ThreadPoolConfig workerPoolConfig = ThreadPoolConfig.defaultConfig();
workerPoolConfig.setCorePoolSize(corePoolSize);
workerPoolConfig.setMaxPoolSize(maxPoolSize);
workerPoolConfig.setPoolName("Worker");
return workerPoolConfig;
}
示例2: LensServer
import org.glassfish.grizzly.threadpool.ThreadPoolConfig; //导入方法依赖的package包/类
/**
* Instantiates a new lens server.
*
* @param conf the conf
* @throws IOException Signals that an I/O exception has occurred.
*/
private LensServer(HiveConf conf) throws IOException {
startServices(conf);
String baseURI = conf.get(LensConfConstants.SERVER_BASE_URL, LensConfConstants.DEFAULT_SERVER_BASE_URL);
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(UriBuilder.fromUri(baseURI).build(), getApp(),
false);
int corePoolSize = conf.getInt(LensConfConstants.GRIZZLY_CORE_POOL_SIZE,
LensConfConstants.DEFAULT_GRIZZLY_CORE_POOL_SIZE);
int maxPoolSize = conf.getInt(LensConfConstants.GRIZZLY_MAX_POOL_SIZE,
LensConfConstants.DEFAULT_GRIZZLY_MAX_POOL_SIZE);
ThreadPoolConfig config = ThreadPoolConfig.defaultConfig();
config.setPoolName("lensserver-pool");
config.setCorePoolSize(corePoolSize);
config.setMaxPoolSize(maxPoolSize);
config.setThreadFactory((new ThreadFactoryBuilder()).setNameFormat("grizzly-http-server-%d")
.setUncaughtExceptionHandler(new JerseyProcessingUncaughtExceptionHandler()).build());
NetworkListener listener = server.getListeners().iterator().next();
listener.getTransport().setWorkerThreadPoolConfig(config);
serverList.add(server);
WebappContext adminCtx = new WebappContext("admin", "");
MetricsServiceImpl metricsService = LensServices.get().getService(MetricsService.NAME);
adminCtx
.setAttribute("com.codahale.metrics.servlets.MetricsServlet.registry", (metricsService.getMetricRegistry()));
adminCtx.setAttribute("com.codahale.metrics.servlets.HealthCheckServlet.registry", metricsService.getHealthCheck());
final ServletRegistration sgMetrics = adminCtx.addServlet("admin", new AdminServlet());
sgMetrics.addMapping("/admin/*");
adminCtx.deploy(server);
}
示例3: configureWorkerThreads
import org.glassfish.grizzly.threadpool.ThreadPoolConfig; //导入方法依赖的package包/类
/**
* See https://grizzly.java.net/coreconfig.html
* See https://grizzly.java.net/bestpractices.html
*/
private void configureWorkerThreads(@NotNull NetworkListener networkListener) {
//WorkerThreadIOStrategy is the default anyway.
//networkListener.getTransport().setIOStrategy(WorkerThreadIOStrategy.getInstance());
ThreadPoolConfig config = ThreadPoolConfig.defaultConfig(); //makes a copy
int numThreads = Runtime.getRuntime().availableProcessors() * 2;
//setting core and max to the same number is important!
config.setCorePoolSize(numThreads);
config.setMaxPoolSize(numThreads);
//a queue limit is optional but recommended
config.setQueueLimit(1000);
networkListener.getTransport().setWorkerThreadPoolConfig(config);
}