本文整理汇总了Java中org.eclipse.jetty.util.thread.ThreadPool类的典型用法代码示例。如果您正苦于以下问题:Java ThreadPool类的具体用法?Java ThreadPool怎么用?Java ThreadPool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ThreadPool类属于org.eclipse.jetty.util.thread包,在下文中一共展示了ThreadPool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testContainerThreadPool
import org.eclipse.jetty.util.thread.ThreadPool; //导入依赖的package包/类
@Test
public void testContainerThreadPool() {
System.setProperty(AthenzConsts.ATHENZ_PROP_MAX_THREADS, "100");
AthenzJettyContainer container = new AthenzJettyContainer();
container.createServer(100);
Server server = container.getServer();
assertNotNull(server);
ThreadPool threadPool = server.getThreadPool();
assertNotNull(threadPool);
// at this point we have no threads so the value is 0
assertEquals(threadPool.getThreads(), 0);
assertEquals(threadPool.getIdleThreads(), 0);
}
示例2: threadPool
import org.eclipse.jetty.util.thread.ThreadPool; //导入依赖的package包/类
private ThreadPool threadPool(Config cfg, ThreadSettingsConfig threadSettingsConfig) {
int maxThreads = threadSettingsConfig.getHttpdMaxThreads();
int minThreads = cfg.getInt("httpd", null, "minthreads", 5);
int maxQueued = cfg.getInt("httpd", null, "maxqueued", 200);
int idleTimeout = (int) MILLISECONDS.convert(60, SECONDS);
int maxCapacity = maxQueued == 0 ? Integer.MAX_VALUE : Math.max(minThreads, maxQueued);
QueuedThreadPool pool =
new QueuedThreadPool(
maxThreads,
minThreads,
idleTimeout,
new BlockingArrayQueue<Runnable>(
minThreads, // capacity,
minThreads, // growBy,
maxCapacity // maxCapacity
));
pool.setName("HTTP");
return pool;
}
示例3: testThreadPool
import org.eclipse.jetty.util.thread.ThreadPool; //导入依赖的package包/类
@Test
public void testThreadPool() throws Exception {
Configuration serverConf = new Configuration();
serverConf.set(WebServerTask.HTTP_MAX_THREADS, 100);
WebServerTask webServerTask = createWebServerTask(new File("target").getAbsolutePath(),
serverConf,
Collections.<WebAppProvider>emptySet(),
true
);
try {
webServerTask.initTask();
Server server = webServerTask.getServer();
assertEquals(100, ((ThreadPool.SizedThreadPool)server.getThreadPool()).getMaxThreads());
} finally {
webServerTask.stopTask();
}
}
示例4: setRuntimeParameters
import org.eclipse.jetty.util.thread.ThreadPool; //导入依赖的package包/类
private void setRuntimeParameters(Server server, Application application) {
ThreadPool pool = server.getThreadPool();
if (pool instanceof QueuedThreadPool) {
QueuedThreadPool qtp = (QueuedThreadPool)pool;
cn.batchfile.getty.application.ThreadPool config = application.getThreadPool();
if (config != null && config.getMaxThreads() > 0) {
qtp.setMaxThreads(config.getMaxThreads());
}
if (config != null && config.getMinThreads() > 0) {
qtp.setMinThreads(config.getMinThreads());
}
if (config != null && config.getIdleTimeout() > 0) {
qtp.setIdleTimeout(config.getIdleTimeout());
}
}
}
示例5: configureThreadPool
import org.eclipse.jetty.util.thread.ThreadPool; //导入依赖的package包/类
private ThreadPool configureThreadPool(final int port) {
final QueuedThreadPool threadPool = new QueuedThreadPool(threadPoolCapacity);
threadPool.setMinThreads(minThreadCount);
threadPool.setMaxThreads(maxThreadCount);
threadPool.setName("Jetty thread pool [" + port + "]");
threadPool.setDetailedDump(true);
return threadPool;
}
示例6: setUp
import org.eclipse.jetty.util.thread.ThreadPool; //导入依赖的package包/类
@Before
public void setUp() {
sut = new ApplicationConfig();
server = mock(Server.class);
registry = mock(InterceptorRegistry.class);
when(server.getThreadPool()).thenReturn(new ThreadPool() {
@Override
public void join() throws InterruptedException {
// Do nothing. This is just a unit test.
}
@Override
public int getThreads() {
return 0;
}
@Override
public int getIdleThreads() {
return 0;
}
@Override
public boolean isLowOnThreads() {
return false;
}
@Override
public void execute(Runnable command) {
// Do nothing. This is just a unit test.
}
});
}
示例7: createServer
import org.eclipse.jetty.util.thread.ThreadPool; //导入依赖的package包/类
private Server createServer(InetSocketAddress address) {
Server server;
if (ClassUtils.hasConstructor(Server.class, ThreadPool.class)) {
server = new Jetty9ServerFactory().createServer(getThreadPool());
}
else {
server = new Jetty8ServerFactory().createServer(getThreadPool());
}
server.setConnectors(new Connector[] { createConnector(address, server) });
return server;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:JettyEmbeddedServletContainerFactory.java
示例8: customThreadPool
import org.eclipse.jetty.util.thread.ThreadPool; //导入依赖的package包/类
@Test
public void customThreadPool() throws Exception {
JettyEmbeddedServletContainerFactory factory = getFactory();
ThreadPool threadPool = mock(ThreadPool.class);
factory.setThreadPool(threadPool);
JettyEmbeddedServletContainer servletContainer = (JettyEmbeddedServletContainer) factory
.getEmbeddedServletContainer();
assertThat(servletContainer.getServer().getThreadPool()).isSameAs(threadPool);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:JettyEmbeddedServletContainerFactoryTests.java
示例9: build
import org.eclipse.jetty.util.thread.ThreadPool; //导入依赖的package包/类
@Override
public Connector build(Server server,
MetricRegistry metrics,
String name,
ThreadPool threadPool) {
_metricRegistry.set(metrics);
return super.build(server, metrics, name, threadPool);
}
示例10: buildConnector
import org.eclipse.jetty.util.thread.ThreadPool; //导入依赖的package包/类
@Override
protected ServerConnector buildConnector(Server server,
Scheduler scheduler,
ByteBufferPool bufferPool,
String name,
ThreadPool threadPool,
ConnectionFactory... factories) {
// Intercept any buildConnector() calls and wrap the provided ConnectionFactory instances with our InstrumentedConnectionFactoryWrapper
InstrumentedConnectionFactoryWrapper connectionFactoryWrappers[] = new InstrumentedConnectionFactoryWrapper[factories.length];
for (int i = 0; i < factories.length; ++i) {
connectionFactoryWrappers[i] = new InstrumentedConnectionFactoryWrapper(factories[i], _metricRegistry.get(), getBindHost(), getPort());
}
return super.buildConnector(server, scheduler, bufferPool, name, threadPool, connectionFactoryWrappers);
}
示例11: createConnector
import org.eclipse.jetty.util.thread.ThreadPool; //导入依赖的package包/类
public ServerConnector createConnector(Server server) {
// a few things are hardcoded for now... if needed we can turn these
// into properties
HttpConfiguration httpConfig = buildHttpConfiguration();
ConnectionFactory[] connectionFactories = buildHttpConnectionFactories(httpConfig);
Scheduler scheduler = new ScheduledExecutorScheduler();
ByteBufferPool bufferPool = buildBufferPool();
// "-1" is Jetty default for acceptor and selector threads that triggers default init algorithm based on
// the number of machine cores
int acceptorThreads = this.acceptorThreads > 0 ? this.acceptorThreads : -1;
int selectorThreads = this.selectorThreads > 0 ? this.selectorThreads : -1;
ThreadPool threadPool = Objects.requireNonNull(server.getThreadPool());
ServerConnector connector = new ServerConnector(
server,
threadPool,
scheduler,
bufferPool,
acceptorThreads,
selectorThreads,
connectionFactories);
connector.setPort(getPort());
connector.setIdleTimeout(30 * 1000);
connector.setHost(getHost());
return connector;
}
示例12: createServer
import org.eclipse.jetty.util.thread.ThreadPool; //导入依赖的package包/类
public Server createServer(Set<MappedServlet> servlets, Set<MappedFilter> filters, Set<MappedListener> listeners) {
ThreadPool threadPool = createThreadPool();
Server server = new Server(threadPool);
server.setStopAtShutdown(true);
server.setStopTimeout(1000L);
server.setHandler(createHandler(servlets, filters, listeners));
if (maxFormContentSize > 0) {
server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", maxFormContentSize);
}
if (maxFormKeys > 0) {
server.setAttribute("org.eclipse.jetty.server.Request.maxFormKeys", maxFormKeys);
}
createRequestLog(server);
Collection<ConnectorFactory> connectorFactories = connectorFactories(server);
Collection<ConnectorDescriptor> connectorDescriptors = new ArrayList<>(2);
if (connectorFactories.isEmpty()) {
LOGGER.warn("Jetty starts with no connectors configured. Is that expected?");
} else {
connectorFactories.forEach(cf -> {
NetworkConnector connector = cf.createConnector(server);
server.addConnector(connector);
connectorDescriptors.add(new ConnectorDescriptor(connector));
});
}
server.addLifeCycleListener(new ServerLifecycleLogger(connectorDescriptors, context));
return server;
}
示例13: threadPool
import org.eclipse.jetty.util.thread.ThreadPool; //导入依赖的package包/类
private ThreadPool threadPool() {
QueuedThreadPool pool = new QueuedThreadPool();
pool.setName("HTTP");
pool.setMinThreads(2);
pool.setMaxThreads(10);
pool.setMaxQueued(50);
return pool;
}
示例14: thatCustomThreadPoolIsUsed
import org.eclipse.jetty.util.thread.ThreadPool; //导入依赖的package包/类
@Test
public void thatCustomThreadPoolIsUsed() throws Exception {
EmbeddedJettyBuilder builder = getBuilder();
builder.withThreadPool(new QueuedThreadPool(20, 5)).createServer();
ThreadPool.SizedThreadPool threadPool = (ThreadPool.SizedThreadPool )builder.buildJetty().getServer().getThreadPool();
assertThat(threadPool.getMaxThreads(), is(20));
assertThat(threadPool.getMinThreads(), is(5));
}
示例15: WebServer
import org.eclipse.jetty.util.thread.ThreadPool; //导入依赖的package包/类
/**
* Creates an instance of the web server but does not actually start
* it. To start it you must call the {@link start} method.
*
* @param config - the mod's core config
*
* @throws IOException thrown when the web socket could not be created and bound
*/
public WebServer(Configuration config) throws IOException
{
// TODO: set this up to use HTTPS instead when requested
webServer = new Server(config.get(WEBSERVER_CONFIG_CATEGORY, "port", 1716).getInt());
webServer.setGracefulShutdown(STOP_WAIT_TIME);
webServer.setSessionIdManager(new HashSessionIdManager());
int maxConnections = config.get(WEBSERVER_CONFIG_CATEGORY, "max-sessions", 20).getInt();
if(maxConnections < 2)
{
LogHelper.warning("The selected number of minimum connections allowed is too low. Using low default instead.");
maxConnections = 2;
}
LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(maxConnections);
ThreadPool tp = new ExecutorThreadPool(2, maxConnections, 60, TimeUnit.SECONDS, queue);
webServer.setThreadPool(tp);
handlers = new RegExContextHandlerCollection();
webServer.setHandler(handlers);
sessionHandler = new SessionHandler();
sessionHandler.getSessionManager().setSessionIdManager(webServer.getSessionIdManager());
addHandler("/", sessionHandler);
rootHandler = new RootHttpHandler();
sessionHandler.setHandler(rootHandler);
resourceHandler = new ResourceHandler();
addHandler("^/resources/.*$", resourceHandler);
rpcHandler = new JsonRpcHandler();
addHandler("/rpc/*", rpcHandler);
}