gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 09:30:51 24 4
gpt4 key购买 nike

我开始使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com