java - 如何在 Heroku 上实现多线程 Jetty RESTful 服务?

标签 java rest heroku jetty threadpool

我正在开始使用 Heroku 网站上的 JAX-RS 教程 ->

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

主要方法如下所示:

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 发生了什么吗?如果我为该进程分配一个 dyno,它是否会自动在线程池中创建多个请求线程来处理 RESTful 请求?如果是,哪些部分是共享/不共享的?

谢谢!

最佳答案

Jetty 只是在这种情况下使用默认值(Jetty 的默认值,而不是 Heroku 的默认值)。您可以像这样更改它:

How to use setThreadPool() in Jetty

关于java - 如何在 Heroku 上实现多线程 Jetty RESTful 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13097557/

相关文章:

java - 如何在 Android Studio 中使用原生 C 库

rest - 在这个 SaaS 场景中,OAuth 是 RESTful API 的好选择吗?

ruby-on-rails - 在 Heroku 上组合和缩小 JS/CSS 的最佳方法

ruby-on-rails - Rails - 迁移错误 - PG::InvalidSchemaName: 错误:

php - 在 Heroku 中部署 Laravel 项目后 MySQL 不起作用

Java Stack Overflow 已经折磨我很久了

java - 如何在登录屏幕上重定向 Spring 安全并发 session 控制 'message'?

java - 在java中实现equals方法

java - 如何动态创建与 wicket 的静态链接?

java - Rest - 响应中的 MediaType 与请求中的 MediaType 相同