Results 1 to 7 of 7
Thread: Spring webservice
- 07-07-2011, 07:20 AM #1
Member
- Join Date
- Dec 2010
- Location
- Bucharest Romania
- Posts
- 40
- Rep Power
- 0
Spring webservice
Hi all,
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.
Thank you
- 07-07-2011, 09:51 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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?
- 07-07-2011, 10:16 AM #3
Member
- Join Date
- Dec 2010
- Location
- Bucharest Romania
- Posts
- 40
- Rep Power
- 0
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?
thanks,
- 07-07-2011, 11:11 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 07-07-2011, 11:57 AM #5
Member
- Join Date
- Dec 2010
- Location
- Bucharest Romania
- Posts
- 40
- Rep Power
- 0
thanks Tools, it works great.
you are the best :)
- 07-07-2011, 02:14 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
It's 2 ells, not 2 ohs...
:)
- 07-07-2011, 02:18 PM #7
Member
- Join Date
- Dec 2010
- Location
- Bucharest Romania
- Posts
- 40
- Rep Power
- 0
Similar Threads
-
possible overlapping jars in spring annotated mvc/spring security project
By savantics in forum Web FrameworksReplies: 1Last Post: 12-27-2010, 05:21 PM -
RestFul Webservice
By deepaksurthi in forum XMLReplies: 0Last Post: 10-26-2010, 01:27 PM -
Please help me in webservice
By javastuden in forum New To JavaReplies: 0Last Post: 10-11-2010, 12:13 PM -
WebService Client
By pravin2008 in forum NetBeansReplies: 3Last Post: 07-23-2008, 01:48 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks