【问题标题】:How to multithread Jetty RESTful service on Heroku?如何在 Heroku 上多线程 Jetty RESTful 服务?
【发布时间】:2012-10-17 08:19:09
【问题描述】:

我开始学习 Heroku 网站上的 JAX-RS 教程->

http://arcane-chamber-8582.herokuapp.com/

main方法如下所示:

package com.example;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;

/**
 *
 * This class launches the web application in an embedded Jetty container.
 * This is the entry point to your application. The Java command that is used for
 * launching should fire this main method.
 *
 */
public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception{
        String webappDirLocation = "src/main/webapp/";

        // The port that we should run on can be set into an environment variable
        // Look for that variable and default to 8080 if it isn't there.
        String webPort = System.getenv("PORT");
        if (webPort == null || webPort.isEmpty()) {
            webPort = "8080";
        }

        Server server = new Server(Integer.valueOf(webPort));
        WebAppContext root = new WebAppContext();

        root.setContextPath("/");
        root.setDescriptor(webappDirLocation + "/WEB-INF/web.xml");
        root.setResourceBase(webappDirLocation);

        // Parent loader priority is a class loader setting that Jetty accepts.
        // By default Jetty will behave like most web containers in that it will
        // allow your application to replace non-server libraries that are part of the
        // container. Setting parent loader priority to true changes this behavior.
        // Read more here: http://wiki.eclipse.org/Jetty/Reference/Jetty_Classloading
        root.setParentLoaderPriority(true);

        server.setHandler(root);

        server.start();
        server.join();
    }

}

我想知道有人可以向我解释一下服务器和 root 发生了什么吗?如果我为这个进程分配一个测功机,它是否会自动在线程池中创建多个请求线程来处理 RESTful 请求?如果有,哪些部分是共享的/不共享的?

谢谢!

【问题讨论】:

  • 具体来说,是否在某个我不知道的地方设置了默认线程池大小?

标签: java rest heroku jetty threadpool


【解决方案1】:

Jetty 只是在该场景中使用默认值(Jetty 的默认值,而不是 Heroku 的)。你可以这样改变它:

How to use setThreadPool() in Jetty

【讨论】:

    猜你喜欢
    • 2013-04-11
    • 2011-12-20
    • 1970-01-01
    • 2013-11-30
    • 2013-04-21
    • 1970-01-01
    • 1970-01-01
    • 2011-08-28
    • 2014-03-25
    相关资源
    最近更新 更多