maxmil
maxmil

Reputation: 410

User initiated background process in a web application

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

Upvotes: 1

Views: 1478

Answers (3)

skaffman
skaffman

Reputation: 403441

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.

Upvotes: 4

Langali
Langali

Reputation: 3207

You could just fire a plain old Java Thread.

Upvotes: -2

KLE
KLE

Reputation: 24159

This sounds typical for an Ajax request. :-)

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

Upvotes: 0

Related Questions