本文整理汇总了Java中org.glassfish.grizzly.threadpool.ThreadPoolConfig类的典型用法代码示例。如果您正苦于以下问题:Java ThreadPoolConfig类的具体用法?Java ThreadPoolConfig怎么用?Java ThreadPoolConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ThreadPoolConfig类属于org.glassfish.grizzly.threadpool包,在下文中一共展示了ThreadPoolConfig类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doOpen
import org.glassfish.grizzly.threadpool.ThreadPoolConfig; //导入依赖的package包/类
@Override
protected void doOpen() throws Throwable {
FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
filterChainBuilder.add(new TransportFilter());
filterChainBuilder.add(new GrizzlyCodecAdapter(getCodec(), getUrl(), this));
filterChainBuilder.add(new GrizzlyHandler(getUrl(), this));
TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance();
ThreadPoolConfig config = builder.getWorkerThreadPoolConfig();
config.setPoolName(CLIENT_THREAD_POOL_NAME)
.setQueueLimit(-1)
.setCorePoolSize(0)
.setMaxPoolSize(Integer.MAX_VALUE)
.setKeepAliveTime(60L, TimeUnit.SECONDS);
builder.setTcpNoDelay(true).setKeepAlive(true)
.setConnectionTimeout(getTimeout())
.setIOStrategy(SameThreadIOStrategy.getInstance());
transport = builder.build();
transport.setProcessor(filterChainBuilder.build());
transport.start();
}
示例2: start
import org.glassfish.grizzly.threadpool.ThreadPoolConfig; //导入依赖的package包/类
public void start(int listenPort, ExecutorService threadpool) throws Exception {
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) threadpool;
ThreadPoolConfig config = ThreadPoolConfig.defaultConfig().copy().setCorePoolSize(threadPoolExecutor.getCorePoolSize())
.setMaxPoolSize(threadPoolExecutor.getMaximumPoolSize()).setPoolName("GRIZZLY-SERVER");
ExecutorService executorService = GrizzlyExecutorService.createInstance(config);
FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
filterChainBuilder.add(new TransportFilter());
filterChainBuilder.add(new GrizzlyProtocolFilter());
filterChainBuilder.add(new GrizzlyServerHandler(executorService));
TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance();
builder.setOptimizedForMultiplexing(true);
builder.setIOStrategy(SameThreadIOStrategy.getInstance());
transport = builder.build();
transport.setProcessor(filterChainBuilder.build());
transport.bind(listenPort);
transport.start();
LOGGER.warn("server started,listen at: " + listenPort);
}
示例3: configureThreadPools
import org.glassfish.grizzly.threadpool.ThreadPoolConfig; //导入依赖的package包/类
private void configureThreadPools(final NetworkListener networkListener, final String poolNamePrefix,
final int workerThreads, final int kernelThreads) {
final TCPNIOTransport transport = networkListener.getTransport();
if (transport.getKernelThreadPoolConfig() == null) {
transport.setKernelThreadPoolConfig(ThreadPoolConfig.defaultConfig());
}
transport.getKernelThreadPoolConfig().setPoolName(poolNamePrefix + "-Kernel").setMaxPoolSize(kernelThreads)
.setCorePoolSize(kernelThreads);
transport.setSelectorRunnersCount(kernelThreads);
if (transport.getWorkerThreadPoolConfig() == null) {
transport.setWorkerThreadPoolConfig(ThreadPoolConfig.defaultConfig());
}
transport.getWorkerThreadPoolConfig().setPoolName(poolNamePrefix + "-Worker").setMaxPoolSize(workerThreads)
.setCorePoolSize(workerThreads);
}
示例4: doOpen
import org.glassfish.grizzly.threadpool.ThreadPoolConfig; //导入依赖的package包/类
@Override
protected void doOpen() throws Throwable {
FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
filterChainBuilder.add(new TransportFilter());
filterChainBuilder.add(new GrizzlyCodecAdapter(getCodec(), getUrl(), this));
filterChainBuilder.add(new GrizzlyHandler(getUrl(), this));
TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance();
ThreadPoolConfig config = builder.getWorkerThreadPoolConfig();
config.setPoolName(CLIENT_THREAD_POOL_NAME)
.setQueueLimit(-1)
.setCorePoolSize(0)
.setMaxPoolSize(Integer.MAX_VALUE)
.setKeepAliveTime(60L, TimeUnit.SECONDS);
builder.setTcpNoDelay(true).setKeepAlive(true)
.setConnectionTimeout(getTimeout())
.setIOStrategy(SameThreadIOStrategy.getInstance());
transport = builder.build();
transport.setProcessor(filterChainBuilder.build());
transport.start();
}
示例5: startRunnables
import org.glassfish.grizzly.threadpool.ThreadPoolConfig; //导入依赖的package包/类
protected void startRunnables(List<ClientRunnable> runnables) {
ThreadPoolConfig tpc = ThreadPoolConfig.defaultConfig().copy().setPoolName("benchmarkclient").setMaxPoolSize(runnables.size())
.setCorePoolSize(runnables.size());
GrizzlyExecutorService executorService = GrizzlyExecutorService.createInstance(tpc);
for (int i = 0; i < runnables.size(); i++) {
ClientRunnable runnable = runnables.get(i);
executorService.execute(runnable);
}
}
示例6: 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;
}
示例7: 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);
}
示例8: 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);
}
示例9: connect
import org.glassfish.grizzly.threadpool.ThreadPoolConfig; //导入依赖的package包/类
private void connect() throws Exception {
this.mgrApi = getMgrAPI();
this.clientEndpoint = new WebSocketClientEndPoint(this.mc, this.mgrApi, this.managerApis);
this.client = ClientManager.createClient();
if (this.mgrApi.isHttps()) {
SSLEngineConfigurator sslEngineConfigurator = new SSLEngineConfigurator(SslContextProvider.getInstance().getSSLContext(), true,
false, false);
this.client.getProperties().put(ClientManager.SSL_ENGINE_CONFIGURATOR, sslEngineConfigurator);
}
//TODO: Future. replace idle timeout with a better way of detecting unreachable server
this.client.setDefaultMaxSessionIdleTimeout(DEFAULT_WEBSOCKET_IDLE_TIMEOUT);
// configuring client properties
this.client.getProperties().put(ClientManager.RECONNECT_HANDLER, this.reconnectHandler);
this.client.getProperties().put(GrizzlyClientContainer.SHARED_CONTAINER, true);
// setting maximum selector thread.
this.client.getProperties().put(
GrizzlyClientSocket.SELECTOR_THREAD_POOL_CONFIG,
ThreadPoolConfig.defaultConfig().setPoolName("WebSocket-Shared-Selector-Thread-Pool")
.setMaxPoolSize(WEBSOCKET_SHARED_THREAD_POOL_SIZE)
.setCorePoolSize(WEBSOCKET_SHARED_THREAD_POOL_SIZE).setQueueLimit(THREAD_QUEUE_LIMIT));
// setting Maximum worker thread
this.client.getProperties().put(
GrizzlyClientSocket.WORKER_THREAD_POOL_CONFIG,
ThreadPoolConfig.defaultConfig().setPoolName("WebSocket-Shared-Worker-Thread-Pool")
.setMaxPoolSize(WEBSOCKET_SHARED_THREAD_POOL_SIZE)
.setCorePoolSize(WEBSOCKET_SHARED_THREAD_POOL_SIZE).setQueueLimit(THREAD_QUEUE_LIMIT));
// creating URI
final String uri = initURI(this.mc, WebSocketClient.this.mgrApi.getPort(), this.mgrApi.getUrl(),
WebSocketClient.this.mgrApi.isHttps());
log.info("Connecting to web socket notifier for MC: " + URI.create(uri));
WebSocketClient.this.wsSession = WebSocketClient.this.client.connectToServer(
WebSocketClient.this.clientEndpoint, getClientEndpointConfig(), URI.create(uri));
log.info("Successfully connected to web socket notifier for MC: " + URI.create(uri));
// Launch Ping thread to keep this connection alive...
startPinging();
}