问题描述
我开始使用Heroku网站上的JAX-RS教程 - >
主要方法如下所示:
package com.example;
导入org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
/ **
*
*该类在嵌入式Jetty容器中启动Web应用程序。
*这是您的应用程序的入口点。用于
*启动的Java命令应该激发这个主要方法。
*
* /
public class Main {b
$ b / **
* @param args
* /
public static void main(String [] args)抛出Exception {
String webappDirLocation =src / main / webapp /;
//我们应该运行的端口可以设置为环境变量
//查找该变量,如果不存在,则默认为8080。
String webPort = System.getenv(PORT);
if(webPort == null || webPort.isEmpty()){
webPort =8080;
}
服务器服务器=新服务器(Integer.valueOf(webPort));
WebAppContext root = new WebAppContext();
root.setContextPath(/);
root.setDescriptor(webappDirLocation +/WEB-INF/web.xml);
root.setResourceBase(webappDirLocation);
//父装载器优先级是Jetty接受的类装入器设置。
//默认情况下,Jetty的行为与大多数Web容器相同,因为它将
//允许您的应用程序替换属于
//容器一部分的非服务器库。将父装载程序优先级设置为true可更改此行为。
//在这里阅读更多:http://wiki.eclipse.org/Jetty/Reference/Jetty_Classloading
root.setParentLoaderPriority(true);
server.setHandler(root);
server.start();
server.join();
}
}
我想知道有没有人可以解释我和服务器和root有什么关系?如果我给这个进程分配了一个dyno,它是否会自动在一个线程池中创建多个请求线程来处理这个RESTful请求?如果是这样,哪些部分共享/不共享?
谢谢!
Jetty仅使用该场景中的默认值(Jetty的默认值,而不是Heroku的)。你可以像这样改变它:
I was getting started with the JAX-RS tutorial on Heroku's site->
http://arcane-chamber-8582.herokuapp.com/
The main method looks like this:
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();
}
}
I was wondering can anybody explain to me what's going on with the server and root? If I assign a dyno to this process, does it automatically create multiple request threads in a thread pool to handle the RESTful requests? If so, which parts are shared/not shared?
Thanks!
Jetty is just using the defaults in that scenario (Jetty's defaults, not Heroku's). You can change it like this:
How to use setThreadPool() in Jetty
这篇关于如何在Heroku上多线程Jetty RESTful服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!