当前位置: 首页>>代码示例>>Java>>正文


Java Server.setThreadPool方法代码示例

本文整理汇总了Java中org.mortbay.jetty.Server.setThreadPool方法的典型用法代码示例。如果您正苦于以下问题:Java Server.setThreadPool方法的具体用法?Java Server.setThreadPool怎么用?Java Server.setThreadPool使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.mortbay.jetty.Server的用法示例。


在下文中一共展示了Server.setThreadPool方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: JettyHttpServer

import org.mortbay.jetty.Server; //导入方法依赖的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: JettyHttpServer

import org.mortbay.jetty.Server; //导入方法依赖的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

示例3: setupHTTPServer

import org.mortbay.jetty.Server; //导入方法依赖的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

示例4: main

import org.mortbay.jetty.Server; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
int port = 8080;
if (args.length != 1) {
	printMessage();
} else {
	int argPort = port;
	try {
		argPort = Integer.parseInt(args[0]);
	} catch (NumberFormatException e) {
		printMessage();
	}
	if (argPort < 0) {
		System.err
				.println("Port number cannot be negative. Reverting to default port 8080.");
		argPort = port;
	}
	port = argPort;
}
Server server = new Server(port);
  	
  	DB db = new DB();
  	
  	db.loadDriver();
  	if (db.isIndexEmpty()) {
  		System.out.println("No indexes found. Please create an index before starting the application.");
  		db.shutdown();
  		System.exit(0);
  	}
  	db.loadCorporaInformation();
  	db.shutdown();
  	
      WebAppContext context = new WebAppContext();
      context.setDescriptor("./server/WEB-INF/web.xml");
      context.setResourceBase("./server");
      context.setContextPath("/");
      context.setParentLoaderPriority(true);

      server.setHandler(context);
      server.setThreadPool(new QueuedThreadPool(500));

      server.start();
      server.join();
  }
 
开发者ID:arne-cl,项目名称:fangorn,代码行数:44,代码来源:StartServer.java

示例5: AzkabanExecutorServer

import org.mortbay.jetty.Server; //导入方法依赖的package包/类
/**
 * Constructor
 *
 * @throws Exception
 */
public AzkabanExecutorServer(Props props) throws Exception {
  this.props = props;

  int portNumber = props.getInt("executor.port", DEFAULT_PORT_NUMBER);
  int maxThreads = props.getInt("executor.maxThreads", DEFAULT_THREAD_NUMBER);

  server = new Server(portNumber);
  QueuedThreadPool httpThreadPool = new QueuedThreadPool(maxThreads);
  server.setThreadPool(httpThreadPool);

  boolean isStatsOn = props.getBoolean("executor.connector.stats", true);
  logger.info("Setting up connector with stats on: " + isStatsOn);

  for (Connector connector : server.getConnectors()) {
    connector.setStatsOn(isStatsOn);
    logger.info(String.format(
        "Jetty connector name: %s, default header buffer size: %d",
        connector.getName(), connector.getHeaderBufferSize()));
    connector.setHeaderBufferSize(props.getInt("jetty.headerBufferSize",
        DEFAULT_HEADER_BUFFER_SIZE));
    logger.info(String.format(
        "Jetty connector name: %s, (if) new header buffer size: %d",
        connector.getName(), connector.getHeaderBufferSize()));
  }

  Context root = new Context(server, "/", Context.SESSIONS);
  root.setMaxFormContentSize(MAX_FORM_CONTENT_SIZE);

  root.addServlet(new ServletHolder(new ExecutorServlet()), "/executor");
  root.addServlet(new ServletHolder(new JMXHttpServlet()), "/jmx");
  root.addServlet(new ServletHolder(new StatsServlet()), "/stats");
  root.addServlet(new ServletHolder(new ServerStatisticsServlet()), "/serverStatistics");

  root.setAttribute(ServerConstants.AZKABAN_SERVLET_CONTEXT_KEY, this);

  executionLoader = createExecLoader(props);
  projectLoader = createProjectLoader(props);
  runnerManager =
      new FlowRunnerManager(props, executionLoader, projectLoader, this
          .getClass().getClassLoader());

  JmxJobMBeanManager.getInstance().initialize(props);

  // make sure this happens before
  configureJobCallback(props);

  configureMBeanServer();
  configureMetricReports();

  SystemMemoryInfo.init(props.getInt("executor.memCheck.interval", 30));

  loadCustomJMXAttributeProcessor(props);

  try {
    server.start();
  } catch (Exception e) {
    logger.warn(e);
    Utils.croak(e.getMessage(), 1);
  }

  logger.info("Azkaban Executor Server started on port " + portNumber);
}
 
开发者ID:JasonBian,项目名称:azkaban,代码行数:68,代码来源:AzkabanExecutorServer.java

示例6: JettyHttpServer

import org.mortbay.jetty.Server; //导入方法依赖的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);
        BaseContext.CTX.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:nince-wyj,项目名称:jahhan,代码行数:47,代码来源:JettyHttpServer.java


注:本文中的org.mortbay.jetty.Server.setThreadPool方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。