I have a Java (Spring MVC) webapp running on Heroku. It uses the setup described in this article: Getting Started with Spring MVC Hibernate on Heroku
It looks like Jetty by default uses just one thread. Given this Heroku & jetty-runner setup, what is the simplest way to increase the threadpool size ?
NB: I do not have any custom Jetty related code (so it's unclear how I'd apply the advice eg at: How to use setThreadPool() in Jetty ). If possible, I'd prefer to keep it that way. Everything Jetty-related is now in Procfile and pom.xml (see below).
Can I set the threadpool size with some jetty-runner parameter or config option? If I need to create a Jetty config file, how do I make Heroku/jetty-runner use it?
Procfile:
web: java $JAVA_OPTS -jar target/dependency/jetty-runner.jar --port $PORT target/*.war
pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-runner</artifactId>
<version>8.1.10.v20130312</version>
<destFileName>jetty-runner.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
I was wrong when I wrote this in the question:
It looks like Jetty by default uses just one thread.
This turned out to be purely a Spring issue. In applicationContext.xml, I changed
<task:annotation-driven/>
into
<task:annotation-driven scheduler="scheduler-pool"/>
<task:scheduler id="scheduler-pool" pool-size="5"/>
... and different @Scheduled
tasks now happily run in separate threads like scheduler-pool-1
or scheduler-pool-3
.
(Before I realised my problem was not a Jetty issue, I had already looked into how Jetty threadpools are configured. Documenting that here; maybe it is useful to someone.)
Create a jetty.xml
config file (somewhere like src/main/resources
so that it gets copied to the compilation target dir), and customise it to your liking.
Example (probably a poor one):
<?xml version="1.0"?>
<!-- For some reason, must use org.eclipse classes,
even though we depend on org.mortbay Jetty... -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Set name="ThreadPool">
<New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
<Set name="minThreads">3</Set>
<Set name="maxThreads">5</Set>
</New>
</Set>
</Configure>
Then, tell jetty-runner to use that config file with the --config
switch. So for example in Heroku's Procfile
, add --config target/classes/jetty.xml
:
web: java $JAVA_OPTS -jar target/dependency/jetty-runner.jar --config target/classes/jetty.xml --port $PORT target/*.war
If you also happen to be using jetty-maven-plugin , you can tell it to use your custom Jetty config by adding this under <configuration>
in pom.xml
:
<jettyConfig>target/classes/jetty.xml</jettyConfig>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.