Results 1 to 7 of 7
  1. #1
    videanuadrian is offline Member
    Join Date
    Dec 2010
    Location
    Bucharest Romania
    Posts
    40
    Rep Power
    0

    Default 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

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,958
    Rep Power
    19

    Default

    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?

  3. #3
    videanuadrian is offline Member
    Join Date
    Dec 2010
    Location
    Bucharest Romania
    Posts
    40
    Rep Power
    0

    Default

    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,

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,958
    Rep Power
    19

    Default

    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.

  5. #5
    videanuadrian is offline Member
    Join Date
    Dec 2010
    Location
    Bucharest Romania
    Posts
    40
    Rep Power
    0

    Default

    thanks Tools, it works great.
    you are the best :)

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,958
    Rep Power
    19

    Default

    It's 2 ells, not 2 ohs...
    :)

  7. #7
    videanuadrian is offline Member
    Join Date
    Dec 2010
    Location
    Bucharest Romania
    Posts
    40
    Rep Power
    0

    Default

    correction!!!

    thanks Tolls, it works great.
    you are the best :)

    i owe you a beer!

Similar Threads

  1. Replies: 1
    Last Post: 12-27-2010, 05:21 PM
  2. RestFul Webservice
    By deepaksurthi in forum XML
    Replies: 0
    Last Post: 10-26-2010, 01:27 PM
  3. Please help me in webservice
    By javastuden in forum New To Java
    Replies: 0
    Last Post: 10-11-2010, 12:13 PM
  4. WebService Client
    By pravin2008 in forum NetBeans
    Replies: 3
    Last Post: 07-23-2008, 01:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •