當前位置: 首頁>>代碼示例>>Java>>正文


Java QueuedThreadPool類代碼示例

本文整理匯總了Java中org.mortbay.thread.QueuedThreadPool的典型用法代碼示例。如果您正苦於以下問題:Java QueuedThreadPool類的具體用法?Java QueuedThreadPool怎麽用?Java QueuedThreadPool使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


QueuedThreadPool類屬於org.mortbay.thread包,在下文中一共展示了QueuedThreadPool類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: JettyHttpServer

import org.mortbay.thread.QueuedThreadPool; //導入依賴的package包/類
public JettyHttpServer(URL url, final HttpHandler handler){
    super(url, handler);
    DispatcherServlet.addHttpHandler(url.getPort(), handler);
    
    int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
    QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setDaemon(true);
    threadPool.setMaxThreads(threads);
    threadPool.setMinThreads(threads);

    SelectChannelConnector connector = new SelectChannelConnector();
    if (! url.isAnyHost() && NetUtils.isValidLocalHost(url.getHost())) {
        connector.setHost(url.getHost());
    }
    connector.setPort(url.getPort());

    server = new Server();
    server.setThreadPool(threadPool);
    server.addConnector(connector);
    
    ServletHandler servletHandler = new ServletHandler();
    ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*");
    servletHolder.setInitOrder(2);
    
    server.addHandler(servletHandler);
    
    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: "
                                        + e.getMessage(), e);
    }
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:34,代碼來源:JettyHttpServer.java

示例2: BayeuxService

import org.mortbay.thread.QueuedThreadPool; //導入依賴的package包/類
/** Instantiate the service.
 * Typically the derived constructor will call {@ #subscribe(String, String)} to 
 * map subscriptions to methods.
 * @param bayeux The bayeux instance.
 * @param name The name of the service (used as client ID prefix).
 * @param maxThreads The size of a ThreadPool to create to handle messages.
 * @param synchronous True if message delivery will be synchronized on the client.
 */
public BayeuxService(Bayeux bayeux,String name, int maxThreads, boolean synchronous)
{
    if (maxThreads>0)
        setThreadPool(new QueuedThreadPool(maxThreads));
    _name=name;
    _bayeux=bayeux;
    _client=_bayeux.newClient(name); 
    _listener=(synchronous)?new SyncListen():new  AsyncListen();
    _client.addListener(_listener);
    
}
 
開發者ID:iMartinezMateu,項目名稱:openbravo-pos,代碼行數:20,代碼來源:BayeuxService.java

示例3: BayeuxLoadGenerator

import org.mortbay.thread.QueuedThreadPool; //導入依賴的package包/類
public BayeuxLoadGenerator() throws Exception
{
    http=new HttpClient();

    http.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
    // http.setConnectorType(HttpClient.CONNECTOR_SOCKET);
    http.setMaxConnectionsPerAddress(20000);

    QueuedThreadPool pool = new QueuedThreadPool();
    pool.setMaxThreads(500);
    pool.setDaemon(true);
    http.setThreadPool(pool);
    http.start();

}
 
開發者ID:iMartinezMateu,項目名稱:openbravo-pos,代碼行數:16,代碼來源:BayeuxLoadGenerator.java

示例4: JettyHttpServer

import org.mortbay.thread.QueuedThreadPool; //導入依賴的package包/類
public JettyHttpServer(URL url, final HttpHandler handler) {
    super(url, handler);
    DispatcherServlet.addHttpHandler(url.getParameter(Constants.BIND_PORT_KEY, url.getPort()), handler);

    int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
    QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setDaemon(true);
    threadPool.setMaxThreads(threads);
    threadPool.setMinThreads(threads);

    SelectChannelConnector connector = new SelectChannelConnector();

    String bindIp = url.getParameter(Constants.BIND_IP_KEY, url.getHost());
    if (!url.isAnyHost() && NetUtils.isValidLocalHost(bindIp)) {
        connector.setHost(bindIp);
    }
    connector.setPort(url.getParameter(Constants.BIND_PORT_KEY, url.getPort()));

    server = new Server();
    server.setThreadPool(threadPool);
    server.addConnector(connector);

    ServletHandler servletHandler = new ServletHandler();
    ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*");
    servletHolder.setInitOrder(2);

    server.addHandler(servletHandler);

    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + url.getParameter(Constants.BIND_IP_KEY) + ":" + url.getParameter(Constants.BIND_PORT_KEY) + ", cause: "
                + e.getMessage(), e);
    }
}
 
開發者ID:hufeng,項目名稱:dubbo2.js,代碼行數:36,代碼來源:JettyHttpServer.java

示例5: createHttpServer

import org.mortbay.thread.QueuedThreadPool; //導入依賴的package包/類
private Server createHttpServer(int port, String name, int maxThreads, int maxIdleTimeMs) throws BioNimbusException {
    try {
        // Creates HTTP Server on int port
        Server httpServer = new Server(port);

        SpecificResponder responder = new SpecificResponder(BioProto.class, bioProto);

        // QueuedThreadPool is jetty's thread pool implementation;
        // this lets us give it a name.
        QueuedThreadPool qtp = new QueuedThreadPool();
        qtp.setName(name);
        qtp.setDaemon(true);
        qtp.setMaxThreads(maxThreads);
        qtp.setMaxIdleTimeMs(maxIdleTimeMs);
        httpServer.setThreadPool(qtp);

        // Creates Responder Servlet
        Servlet servlet = new ResponderServlet(responder);

        // Creates Context adding a holder
        new Context(httpServer, "/").addServlet(new ServletHolder(servlet), "/*");

        // Return the early created Server
        return httpServer;
    } catch (Exception e) {
        throw new BioNimbusException(e);
    }
}
 
開發者ID:bionimbuz,項目名稱:Bionimbuz,代碼行數:29,代碼來源:AvroServer.java

示例6: go

import org.mortbay.thread.QueuedThreadPool; //導入依賴的package包/類
public void go() {
  QueuedThreadPool pool = new QueuedThreadPool();
  pool.setMinThreads(2); // debug server doesn't need many threads.
  pool.setMaxThreads(10);
  pool.setName("DebugServer(port" + port + ")");
  pool.setDaemon(true);
  server.setThreadPool(pool);
  SocketConnector connector = new SocketConnector();

  connector.setPort(port);
  connector.setHost(host);
  connector.setMaxIdleTime(60000); // 1 min
  server.addConnector(connector);

  context.setContextPath("/");
  context.setBaseResource(Resource.newClassPathResource("/org/cloudera/stethoscope"));
  server.setHandler(context);

  addServlet(new DefaultServlet(), "/");
  addServlet(new DataServlet(), "/json/*");
  addServlet(new TracerServlet(inst), "/tracer/*");
  addServlet(new EvaluateServlet(), "/evaluate");
  addServlet(new PoorMansProfileServlet(), "/poorMansProfiler");
  addServlet(new JMXJsonServlet(), "/jmx");
  
  // addServlet(new LoggerServlet(), "/logging");
  
  try {
    server.start();
  } catch (Exception e) {
    // avoiding logging in this context.
    e.printStackTrace(System.err);
  }
}
 
開發者ID:philz,項目名稱:stethoscope,代碼行數:35,代碼來源:StethoscopeWebServer.java

示例7: HttpServer

import org.mortbay.thread.QueuedThreadPool; //導入依賴的package包/類
/**
 * Create a status server on the given port.
 * The jsp scripts are taken from src/webapps/<name>.
 * @param name The name of the server
 * @param port The port to use on the server
 * @param findPort whether the server should start at the given port and 
 *        increment by 1 until it finds a free port.
 * @param conf Configuration 
 */
public HttpServer(String name, String bindAddress, int port,
    boolean findPort, Configuration conf) throws IOException {
  webServer = new Server();
  this.findPort = findPort;

  listener = createBaseListener(conf);
  listener.setHost(bindAddress);
  listener.setPort(port);
  webServer.addConnector(listener);

  int maxThreads = conf.getInt(HTTP_MAX_THREADS, -1);
  // If HTTP_MAX_THREADS is not configured, QueueThreadPool() will use the 
  // default value (currently 254).
  QueuedThreadPool threadPool = maxThreads == -1 ?
      new QueuedThreadPool() : new QueuedThreadPool(maxThreads);
  webServer.setThreadPool(threadPool);

  final String appDir = getWebAppsPath();
  ContextHandlerCollection contexts = new ContextHandlerCollection();
  webServer.setHandler(contexts);

  webAppContext = new WebAppContext();
  webAppContext.setContextPath("/");
  webAppContext.setWar(appDir + "/" + name);
  webAppContext.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, conf);
  webServer.addHandler(webAppContext);

  addDefaultApps(contexts, appDir);

  addGlobalFilter("safety", QuotingInputFilter.class.getName(), null);
  final FilterInitializer[] initializers = getFilterInitializers(conf); 
  if (initializers != null) {
    for(FilterInitializer c : initializers) {
      c.initFilter(this);
    }
  }
  addDefaultServlets();
}
 
開發者ID:iVCE,項目名稱:RDFS,代碼行數:48,代碼來源:HttpServer.java

示例8: HttpServer

import org.mortbay.thread.QueuedThreadPool; //導入依賴的package包/類
/**
 * Create a status server on the given port.
 * The jsp scripts are taken from src/webapps/<name>.
 * @param name The name of the server
 * @param port The port to use on the server
 * @param findPort whether the server should start at the given port and 
 *        increment by 1 until it finds a free port.
 * @param conf Configuration 
 */
public HttpServer(String name, String bindAddress, int port,
    boolean findPort, Configuration conf) throws IOException {
  webServer = new Server();
  this.findPort = findPort;

  listener = createBaseListener(conf);
  listener.setHost(bindAddress);
  listener.setPort(port);
  webServer.addConnector(listener);

  webServer.setThreadPool(new QueuedThreadPool());

  final String appDir = getWebAppsPath();
  ContextHandlerCollection contexts = new ContextHandlerCollection();
  webServer.setHandler(contexts);

  webAppContext = new WebAppContext();
  webAppContext.setContextPath("/");
  webAppContext.setWar(appDir + "/" + name);
  webServer.addHandler(webAppContext);

  addDefaultApps(contexts, appDir);

  final FilterInitializer[] initializers = getFilterInitializers(conf); 
  if (initializers != null) {
    for(FilterInitializer c : initializers) {
      c.initFilter(this);
    }
  }
  addDefaultServlets();
}
 
開發者ID:thisisvoa,項目名稱:hadoop-0.20,代碼行數:41,代碼來源:HttpServer.java

示例9: StreamingMarketQuote

import org.mortbay.thread.QueuedThreadPool; //導入依賴的package包/類
public StreamingMarketQuote() throws ModelException
{
	client.setThreadPool(new QueuedThreadPool(250));
	client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
	client.setMaxConnectionsPerAddress(500); // max 200 concurrent connections to every address
	try
	{
		client.start();
	}
	catch (Exception e)
	{
		throw new ModelException("Start HTTP Client", e);
	}
}
 
開發者ID:Ccook,項目名稱:conniption,代碼行數:15,代碼來源:StreamingMarketQuote.java

示例10: startUp

import org.mortbay.thread.QueuedThreadPool; //導入依賴的package包/類
@Override
protected void startUp() throws Exception {
  // setup the jetty config
  ServletHolder sh = new ServletHolder(ServletContainer.class);
  sh.setInitParameter("com.sun.jersey.config.property.packages", "com.twitter.hraven.rest");
  sh.setInitParameter(JSONConfiguration.FEATURE_POJO_MAPPING, "true");

  server = new Server();

  Connector connector = new SelectChannelConnector();
  connector.setPort(this.port);
  connector.setHost(address);

  server.addConnector(connector);

  // TODO: in the future we may want to provide settings for the min and max threads
  // Jetty sets the default max thread number to 250, if we don't set it.
  //
  QueuedThreadPool threadPool = new QueuedThreadPool();
  server.setThreadPool(threadPool);

  server.setSendServerVersion(false);
  server.setSendDateHeader(false);
  server.setStopAtShutdown(true);
  // set up context
  Context context = new Context(server, "/", Context.SESSIONS);
  context.addServlet(sh, "/*");

  // start server
  server.start();
}
 
開發者ID:twitter,項目名稱:hraven,代碼行數:32,代碼來源:RestServer.java

示例11: startInner

import org.mortbay.thread.QueuedThreadPool; //導入依賴的package包/類
@Override
public void startInner() {
    try {
        Connector connector = new SelectChannelConnector();
        connector.setLowResourceMaxIdleTime(3000);
        connector.setPort(this.port);
        QueuedThreadPool threadPool = new QueuedThreadPool();
        threadPool.setName("VoldemortHttp");
        threadPool.setMaxThreads(this.numberOfThreads);
        Server httpServer = new Server();
        httpServer.setConnectors(new Connector[] { connector });
        httpServer.setThreadPool(threadPool);
        httpServer.setSendServerVersion(false);
        httpServer.setSendDateHeader(false);
        Context context = new Context(httpServer, "/", Context.NO_SESSIONS);
        context.setAttribute(VoldemortServletContextListener.SERVER_KEY, server);
        context.setAttribute(VoldemortServletContextListener.VELOCITY_ENGINE_KEY,
                             velocityEngine);
        context.addServlet(new ServletHolder(new AdminServlet(server, velocityEngine)),
                           "/admin");
        context.addServlet(new ServletHolder(new StoreServlet(requestHandler)), "/stores");
        context.addServlet(new ServletHolder(new ReadOnlyStoreManagementServlet(server,
                                                                                velocityEngine)),
                           "/read-only/mgmt");
        context.addServlet(new ServletHolder(new StatusServlet(server, velocityEngine)),
                           "/server-status");
        this.context = context;
        this.httpServer = httpServer;
        this.httpServer.start();
        logger.info("HTTP service started on port " + this.port);
    } catch(Exception e) {
        throw new VoldemortException(e);
    }
}
 
開發者ID:we7,項目名稱:voldemort,代碼行數:35,代碼來源:HttpService.java

示例12: setThreads

import org.mortbay.thread.QueuedThreadPool; //導入依賴的package包/類
/**
 * Set the min, max number of worker threads (simultaneous connections).
 */
public void setThreads(int min, int max) {
  QueuedThreadPool pool = (QueuedThreadPool) webServer.getThreadPool();
  pool.setMinThreads(min);
  pool.setMaxThreads(max);
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:9,代碼來源:HttpServer2.java

示例13: JettyHttpServer

import org.mortbay.thread.QueuedThreadPool; //導入依賴的package包/類
public JettyHttpServer(URL url, final HttpHandler handler){
        super(url, handler);

        // modified by lishen
        this.url = url;
        // TODO we should leave this setting to slf4j
        Log.setLog(new StdErrLog());
        Log.getLog().setDebugEnabled(false);

        DispatcherServlet.addHttpHandler(url.getPort(), handler);

        int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
        QueuedThreadPool threadPool = new QueuedThreadPool();
        threadPool.setDaemon(true);
        threadPool.setMaxThreads(threads);
        threadPool.setMinThreads(threads);

        SelectChannelConnector connector = new SelectChannelConnector();
        if (! url.isAnyHost() && NetUtils.isValidLocalHost(url.getHost())) {
            connector.setHost(url.getHost());
        }
        connector.setPort(url.getPort());

        server = new Server();
        server.setThreadPool(threadPool);
        server.addConnector(connector);

        ServletHandler servletHandler = new ServletHandler();
        ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*");
        servletHolder.setInitOrder(2);

        // modified by lishen
        // dubbo's original impl can't support the use of ServletContext
//        server.addHandler(servletHandler);
        // TODO Context.SESSIONS is the best option here?
        Context context = new Context(server, "/", Context.SESSIONS);
        context.setServletHandler(servletHandler);
        ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext());

        try {
            server.start();
        } catch (Exception e) {
            throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: "
                                            + e.getMessage(), e);
        }
    }
 
開發者ID:zhuxiaolei,項目名稱:dubbo2,代碼行數:47,代碼來源:JettyHttpServer.java

示例14: setThreads

import org.mortbay.thread.QueuedThreadPool; //導入依賴的package包/類
/**
 * Set the min, max number of worker threads (simultaneous connections).
 */
public void setThreads(int min, int max) {
  QueuedThreadPool pool = (QueuedThreadPool) webServer.getThreadPool() ;
  pool.setMinThreads(min);
  pool.setMaxThreads(max);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:9,代碼來源:HttpServer.java

示例15: setupHTTPServer

import org.mortbay.thread.QueuedThreadPool; //導入依賴的package包/類
private void setupHTTPServer() throws IOException {
  TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
  TProcessor processor = new Hbase.Processor<Hbase.Iface>(handler);
  TServlet thriftHttpServlet = new ThriftHttpServlet(processor, protocolFactory, realUser,
      conf, hbaseHandler, securityEnabled, doAsEnabled);

  httpServer = new Server();
  // Context handler
  Context context = new Context(httpServer, "/", Context.SESSIONS);
  context.setContextPath("/");
  String httpPath = "/*";
  httpServer.setHandler(context);
  context.addServlet(new ServletHolder(thriftHttpServlet), httpPath);

  // set up Jetty and run the embedded server
  Connector connector = new SelectChannelConnector();
  if(conf.getBoolean(THRIFT_SSL_ENABLED, false)) {
    SslSelectChannelConnector sslConnector = new SslSelectChannelConnector();
    String keystore = conf.get(THRIFT_SSL_KEYSTORE_STORE);
    String password = HBaseConfiguration.getPassword(conf,
        THRIFT_SSL_KEYSTORE_PASSWORD, null);
    String keyPassword = HBaseConfiguration.getPassword(conf,
        THRIFT_SSL_KEYSTORE_KEYPASSWORD, password);
    sslConnector.setKeystore(keystore);
    sslConnector.setPassword(password);
    sslConnector.setKeyPassword(keyPassword);
    connector = sslConnector;
  }
  String host = getBindAddress(conf).getHostAddress();
  connector.setPort(listenPort);
  connector.setHost(host);
  connector.setHeaderBufferSize(1024 * 64);
  httpServer.addConnector(connector);

  if (doAsEnabled) {
    ProxyUsers.refreshSuperUserGroupsConfiguration(conf);
  }

  // Set the default max thread number to 100 to limit
  // the number of concurrent requests so that Thrfit HTTP server doesn't OOM easily.
  // Jetty set the default max thread number to 250, if we don't set it.
  //
  // Our default min thread number 2 is the same as that used by Jetty.
  int minThreads = conf.getInt(HTTP_MIN_THREADS, 2);
  int maxThreads = conf.getInt(HTTP_MAX_THREADS, 100);
  QueuedThreadPool threadPool = new QueuedThreadPool(maxThreads);
  threadPool.setMinThreads(minThreads);
  httpServer.setThreadPool(threadPool);

  httpServer.setSendServerVersion(false);
  httpServer.setSendDateHeader(false);
  httpServer.setStopAtShutdown(true);

  LOG.info("Starting Thrift HTTP Server on " + Integer.toString(listenPort));
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:56,代碼來源:ThriftServerRunner.java


注:本文中的org.mortbay.thread.QueuedThreadPool類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。