views:

24

answers:

2

I have a web application running over Jetty, and I need to spawn a thread for idle connection handling. This thread is being started in the spring context.

I know it's not a good practice to spawn threads in a container, but couldn't find a better way to do this. Any ideas?

A: 

You can have the container set up a timer or thread pool for you. See the docs.

Aaron Novstrup
And HttpClientManager is a Thread? or calls Thread.start()? I think you're better off making it a Runnable or TimerTask, and then using Spring's scheduling/pooling support. But you might also find this to be of interest: http://denistek.blogspot.com/2008/10/spawn-thread-in-servlet.html
Aaron Novstrup
This might be helpful as well: http://www.springbyexample.org/examples/embedded-spring-web-services.html
Aaron Novstrup
Thanks! Task scheduler solves the problem!
fst
A: 

The traditional way to handle such resources is in a servlet context listener. Check the Servlet API.

Thorbjørn Ravn Andersen