webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

Handling service.doThreadInvoke()

  • 1.  Handling service.doThreadInvoke()

    Posted Fri February 15, 2008 10:00 AM

    Hi, there…

    Is there any way to know if the service i have run using service.doThreadInvoke() in java service have been finished or still running?
    I have read some of thread in this forum, they recommand using ServiceThread which is the output from the service.doThreadInvoke(). But how to use this class?
    I have looking about this class in the API doc, but i couldn’t find it. Does any one have documentation about ServiceThread? or any solution of my problem?

    Thank’s before…


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 2.  RE: Handling service.doThreadInvoke()

    Posted Fri February 15, 2008 12:07 PM

    The service you invoked on its own thread must use pub.sync:notify to communicate its results to the parent (spawning) service. The parent service must use pub.sync:wait if it needs to obtain the output of the child service.

    If the wait timeout period expires before results are returned, you don’t have a way to see if the spawned thread is still running or if it died silently. That’s why I recommend taking care to not simply throw exceptions in a spawned service but to use notifyOnSuccess / notifyOnError approach.

    If your wait timeout period is too short, the parent thread will give up on the child thread that is still happily doing its thing. You can either make the wait period longer or use a repeat statement. So long as you are always notifying correctly, if your results aren’t back you can assume the service is still running.

    Of course, you could create some logic in which a spawned thread uses some type of semaphore to indicate it is running, but that sounds like unnecessary complexity.

    HTH,

    Mark


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 3.  RE: Handling service.doThreadInvoke()

    Posted Fri February 15, 2008 05:03 PM

    In addition to the threading advice from Mark, one should also consider whether a threaded invoke is really, really necessary. If the assumption is that it will make things faster, you’ll want to verify that assumption before committing to the complexity of a multi-threaded solution.


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 4.  RE: Handling service.doThreadInvoke()

    Posted Tue February 19, 2008 03:06 AM

    Hi Mark, i have read about usage of pub.sync:notify and pub.sync:wait.
    In my case there’s one service as a parent who’s called two other service as a thread. If I use this wait and notify, can I get the an output for each service that I invoke using thread?
    Should I call pub.sync:wait twice to get the output for each service?

    Can you give me an example about usage of pub.sync:notify and pub.sync:wait in a java service?

    Thank’s for the warning Rob, but i have no other solution for my case than invoke the thread.

    Sorry if I’am asking to much, cause i’m newbie to webMethods…
    Thank’s for all your help…


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 5.  RE: Handling service.doThreadInvoke()

    Posted Tue February 19, 2008 04:40 AM

    Yes, you’ll need to make two calls to pub.sync:wait. Each will use a unique key to get the results from the spawned thread. Ideally, you’ll check first for the results of the task that you expect to have the shorter run time, then the longer running one.

    Look at the “thread” examples in the WmSamples folder available fror download from Advantage.

    Mark


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 6.  RE: Handling service.doThreadInvoke()

    Posted Tue February 19, 2008 06:57 AM

    Hi mark, i have tried use wait and notify, and it’s work.
    And i have a few another question :smiley:

    • How if I don’t know when the child thread will end?
    • If the notify called earlier than the wait, still the wait method can get the notify message?
    • How long the value of notify will live in server? (For example the thread call notify at 10.44 and the parent just call the wait at 11.00, is the parent still get the notify?)

    Thanks again…


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 7.  RE: Handling service.doThreadInvoke()

    Posted Tue February 19, 2008 04:50 PM

    The parent thread will not know when the child will end. If you you don’t know which of two child threads will end first then just wait for them in the order that you spawned them.

    Yes. The wait will just be used to obtain the results, if the child thread is already completed there will be no pause.

    Never tested this and you should never use multi-threading for this type of long-running process. In theory the results should still be available.

    Mark


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 8.  RE: Handling service.doThreadInvoke()

    Posted Wed February 20, 2008 01:59 AM

    Thank’s Mark for all your help.
    It’s really help me… :slight_smile:


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 9.  RE: Handling service.doThreadInvoke()

    Posted Thu August 08, 2019 06:12 AM

    seen in 7.1.2/7-1-1_Integration_Server_Java_API_Reference/com/wm/app/b2b/server/ServiceThread.html
    "To join this thread and get the results of the service invocation, you call the getIData() method, which returns the pipeline of the service running in this thread when that service is completed. "

    AFAIK it is the same in newer versions


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods