i have an app written with spring+jpa+hibernate+struts2 that runs on glassfish3.1. I have created a webservice as a bean spring. The problem is that when this service runs i have to log the data that was received by the WS and then to do other task that can take up to15 min to complete. But i want to send the response back to my caller imeadtly and not after 5-10-15 mins when that tasks finishes.
Do i have to create a new thread and to launch this task in that thread?
How can i implement this in a app that uses spring IoC. I have to mention that the time consuming task did not affect the ws response in any way. That`s just a task that i have to do for each ws call.
So, just so I understand, you have a request come into the service, and you need to do a load of time-consuming stuff off to the side that isn't directly relevant to gettign a response back to the client?
Launching a thread sounds reasonable to me. It's essentially what you'd be doing if you used messaging or quartz to handle this for you. Indeed, one of those techniques might be a good fit?
Hi Tools, thanks for the reply. Yes you understood the problem completely. I saw that quartz is a "cron engine", and this is not what i`m looking for, as for the messages i have no ideea hot to implement this :) .
My question now is :
how do i spwn a new thread ? due the fact that i use a JEE environment (glassfish3.1) to run my app, and my webservice is a spring bean. Do i have to inherit Thread or implent runnable like any other java program that uses threads or do i have to do something special?
For a new Thread simply write a class (could be an anonymous inner class) that implements Runnable.
The API has an example. The second example is the way to do it. extending Thread is not considered good practice.
thanks Tools, it works great.
you are the best :)
It's 2 ells, not 2 ohs...
thanks Tolls, it works great.
you are the best :)
i owe you a beer!