Dan
Dan

Reputation: 1033

EmbeddedTomcat and startStopThreads attribute

I've been looking all around and cannot find any good explanations or examples of using Spring 4.x (Springboot) with an EmbdeddedTomcat container and manually setting the startStopThreads attribute described here

I've noticed our application's startup latency has been getting worse over time, but also see (in the logs) the thread pool labeled [localhost-startStop-1] is the only thread ever executing beyond [main]. I would like to add more threads into this pool to speed up our asynch startup.

Can anybody help me with Tomcat's startStopThreads issue?


UPDATE -
A good usecase for this is dynamically creating DynamoDb tables upon startup. The creation code is wrapped in an Executor.submit call, however the logs show these being executed serially. Here's an example of whats in the logs:

2017-02-22 15:000:000:01,000 [main                 ] INFO Creating table 1 
2017-02-22 15:000:000:05,000 [localhost-startStop-1] INFO Creating table 2
2017-02-22 15:000:000:10,000 [localhost-startStop-1] INFO Creating table 3

Unfortunately, I am never seeing localhost-startStop-2 execute anything, which it should if it were in the threadpool

Upvotes: 0

Views: 1739

Answers (1)

Andy Wilkinson
Andy Wilkinson

Reputation: 116111

Configuring startStopThreads won't have any effect. It's used by each container in Tomcat (Service, Host, Context, etc) when starting their children. With more than one thread available a container with multiple children will start them in parallel. It won't have any effect in a typical Spring Boot application as each Tomcat container only has a single child.

Rather than trying to use Tomcat's threads to perform some initialisation in parallel, I'd recommend using a Java Executor or Spring Framework's TaskExecutor.

Upvotes: 1

Related Questions