Thread sleep

Hi,

can some help me with the thread.sleep
i want to execute a flow service that has 2 adapter services
i want to run the first adapter service first and give a 1 minute wait time and execute the second adapter service can i use the threrad.sleep or can i use the sync.wait

SEQUENCE
FLOWSERVICEXYZ
>>>ADAPTER SERVICE A
>>>THREAD.SLEEP/WAIT
>>>>ADAPTER SERVICE B
SEQUENCE

thanks for the help in adavance

Thx
Rohit

Is your requirement to always wait for a minute before kicking off the second adapter service? If so, you can create a simple java service modeled after the sample.threads.utils.stall java service located in WmSamples. This will force a sleep of n seconds after adapter service A completes.

If, on the other hand, you want to wait UP TO one minute after invoking adapter service A, before kicking off adapter service B, then you’ll need to create a java service that uses the Service.doThreadedInvoke() API method to invoke a Flow or java service on its own thread.

When the service that is invoked completes, it needs to return its results using pub.sync:notify using a key that you pass to it. I prefer to wrap pub.sync:notify with my own java service in order to provide a means of returning exception info from a service invoked on a separate thread.

Your calling service calls your doThreadedInvoke service to kick of adapter service a, then invokes pub.sync:wait with a wait time of n seconds. If the wait time expires before adapter service A returns results, your pub.sync:wait will throw an exception. You can wrap this in a try-catch structure so that your catch behavior can be changed to not throw an exception, but simply to continue processing with adapter service B.

See this post for additional comments on exception handling in service invoked using doThreadedInvoke.

Mark

Mark i have used sleep misc.sleep service its working fine for me now
but i am not sure its the right functionality i am using to stop the adapter service for one minute and start the second adapter seevice,

Thnaks
Rohit

Rohit,

Using thread.sleep in the calling service won’t make your adapter service sleep, it will just sleep for one minute after adapter service A completes.

I’m still not sure what you are tying to accomplish with this. Perhaps you could share a bit more of the requirement.

Mark

Hi Rohit

You can also use Repeat function and do thbe sleep functionality

Call the Adapter Service A
Repeat ( set the Count 1 and RepeatInterval to 60 )
map ( dummy one)
Call the Adapter Service B

This way the sleep functionality can be achived.

Hope this helped.
Thanks

Hi Rohit

You can also use Repeat function and do the sleep functionality

Call the Adapter Service A
Repeat ( set the Count 1 and RepeatInterval to 60 )
map ( dummy one)
Call the Adapter Service B

This way the sleep functionality can be achieved.

Hope this helped.
Thanks

Rakesh,

The advantage of a sleep over a busy-loop is that you don’t burn up cpu cycles executing a dummy map step.

Regards

Thanks for the reply marks/rakesh,

Mark carlson can u please be more specific with the jave code for implementing the the Service.doThreadedInvoke() so that i can work around with this and look if it works for me,

Thnanks
Rohit

Rohit,

The WmSamples packages has an example in the threads folder.

Basically you do the following:

  1. build an IData with the inputs to the service you wish to invoke (this is often done by making a deep or shallow clone of an input document) []insert a variable called “key” into that IData that contains the key of the service to be notified with the results. []invoke your service using something like this:
    [quote]
    ServiceThread st = null; st=Service.doThreadInvoke(svcName, inputClone);
    [/quote]
    the invoked service is responsible for invoking pub.sync:notify using the key inserted into the input document to return its results to the waiting service. Note: if the invoked service throws an exception, nothing will catch it and its results will not be returned. Hence the suggestion to wrap pub.sync:notify so that it returns a return code and an error message if some exception has occurred

HTH,

Lots more discussion on doThreadedInvoke is available in past forum messages. The search function is your friend.

Mark (edited to fix typo in code snippet)

(Message edited by mcarlson on July 05, 2005)

(Message edited by mcarlson on July 05, 2005)