views:

305

answers:

3

I have a java web application wired using Spring on Tomcat.

I need a way for a user to initiate a background process in the server and return a response to the user without waiting for the background process to complete.

The background process is programmed in java and integrated with my application.

Since i am using tomcat JMS is not an option. I'd rather not have to customize my tomcat installation for the sake of portability.

I could use Quartz or similar and check on a regular basis whether the process should run but i'd prefer something that started instantly.

I have tried spawning a new thread but it is not aware of my Spring beans.

What is the best way to go about this?

Thanks

Max

A: 

This sounds typical for an Ajax request. :-)

Your browser won't be waiting for the result...

KLE
A: 

You could just fire a plain old Java Thread.

Langali
hello, downvote?
Langali
+3  A: 

Spring provides the TaskExecutor abstraction for this sort of thing, which comes with a dozen or so different implementations for you to choose from (ThreadPoolTaskExecutor is probably what you want). It's up to you to use it correctly so that the tasks have access to the Spring context when they run.

skaffman
Great TaskExecutor looks like my man.