Re: parallel processes and thread.sleep

Monique Maker <[email protected]> Fri, 19 Aug 2005 11:50:36 +0300
Newsgroups gmane.comp.java.enhydra.shark
Message-ID <[email protected]>
Hello He Wei,

If your application is running in an application server, I think that the Scheduler ToolAgent is not the best choice.

I would like to warn you that, with or without an application server, you will need to limit the number of simultaneously running threads.

Note that Shark is not good suited to run in multi-threading environment - it aborts any batch executions (such as deadlines recalculation) on process lock timout (or any other error). As you say, your activity (probably "moving") is running significantly longer than the process lock timeout. Our experience is that if some activity runs for more than the lock timout (which is about one second by default), the deadlines recalculation (this is where we are using multi-threading in Shark) fails on the first process lock timeout and the mutli-threading becomes unusable. To be more specific, imagine a process that executes some activity, then waits a pre-defined period of time (a deadline condition) to continue and the next activity runs a long time. Now imagine several instances of this process. We call the deadlines recalculation on timer. On each timer tick Shark is contacted in a new thre
 ad. When one instance of the process proceeds after the deadline and the next tick of the
 timer tries to proceed another process, the deadline recalculation fails because the first process instance is still locked. Therefore the next process instances cannot be proceed before the long-running activity of the first instance fiishes nad allows Shark to unlock the process.

Also note that Shark uses between five and ten database connections (for our relatively simple processes) despite of its own and application server's database connection pools. Also Shark does not release database connections on (some) exceptions. This means that you might need to restart periodically your application to release the database connections. These are two of the reasons you will need to limit the number of simultaneous Shark threads.

Best Regards,
Monique

He Wei wrote:
> Hello Monique,
> 
> Thank you for your code and suggestion.
> My process is to handle several items simultaneously. Each of the items will
> go through the same process, such as: unloading -> moving -> loading. If we
> have, say, 10 items coming, 10 process instances at the same time will be
> initiated to handle them. That is the reason why I need to run several
> processes in parallel. 
> Each process will take 30 seconds to complete. When initiating them in
> different threads, the process 2 will wait 30s until process 1 completes. Is
> the 30s considered too "fast" to shark?
> I am testing on using Scheduler tool-agent in the process. It looks
> promising. 
> Thank you.
> Best Regards,
> He Wei
> 
> -----Original Message-----
> From: Monique Maker [mailto:[email protected]] 
> Sent: Wednesday, August 17, 2005 6:01 PM
> To: [email protected]
> Subject: Re: [shark] parallel processes and thread.sleep
> 
> Hello He Wei,
> 
> Probably your processes are "too fast" (as they should be according to Shark
> documentation) and each process manages to run in a single thread "switch",
> i.e. before the JVM manages to give execution time to another thread.
> 
> Please explain why do you need to run several processes in parralel.
> 
> Please note that (almost) any solution will be similar to Java execution of
> one and the same code in non-synchronized threads - you never know what part
> of the code is executed in each thread.
> 
> Best Regards,
> Monique
> 
> He Wei wrote:
> 
>>Hello Vlada,
>>
>>I have tested according to what you suggested to start a new thread for
> 
> each
> 
>>process instance. However the results show they are still running in
>>sequence based on the sequence to run them, but not in parallel. Could you
>>please kindly advice further? Thank you very much.
>>(pl. my process contains only automatic activities.)
>>Best Regards,
>>He Wei
>>
>>-----Original Message-----
>>From: Vladimir Puskas [mailto:[email protected]] 
>>Sent: Wednesday, August 17, 2005 3:54 PM
>>To: [email protected]
>>Subject: Re: [shark] parallel processes and thread.sleep
>>
>>Hello He Wei
>>
>>you wrote:
>>
>>
>>>Dear Vlada,
>>>
>>>Regarding to the question in the email below, could you please kindly
>>>explain more how to "let your application start a new Thread for those 5
>>>instances" to make it *really* parallel?
>>
>>
>>Since Shark does not start a new thread, your application must, for 
>>scenario you described.
>>
>>       //final SharkConnection sc;
>>       //final Map workflowRelevantData;
>>       for (int i = 0; i < 5; i++) {
>>          new Thread() {
>>             public void run() {
>>                try {
>>                   WfProcess theProcess = sc.createProcess("pkg","pdef");
>>                   theProcess.set_process_context(workflowRelevantData);
>>                   theProcess.start();
>>                } catch (RootException e) {
>>                   e.printStackTrace();
>>                }
>>             }
>>          }.start();
>>       }
>>
>>
>>
>>
>>>Thank you very much.
>>>Best Regards,
>>>He Wei
>>>
>>>-----Original Message-----
>>>From: Vladimir Puskas [mailto:[email protected]] 
>>>Sent: Wednesday, July 20, 2005 4:55 PM
>>>To: [email protected]
>>>Subject: Re: [shark] parallel processes and thread.sleep
>>>
>>>Hello Sebastian
>>>
>>>you wrote:
>>>
>>>
>>>
>>>>hi list,
>>>>
>>>>i try to realise some parallel processes (instances) and each of them
>>>>uses the javascript-agent with java.lang.thread.sleep(20000). after that
>>>>break, the process sends an email. now, i have the following problem:
>>>>i start 5 processes at the same time.
>>>>the first process starts, waits 20 seconds and sends an email.
>>>>then, after that 20 seconds, the second process waits 20 seconds and
>>>>sends an email.
>>>>then, after 40 seconds, the thrid process waits 20 seconds and sends an
>>>>email.
>>>>...
>>>>is it possible, that all the processes start at the same time, wait 20
>>>>seconds and send then an email? i tried the beer pause example too -
>>>>same result.
>>>
>>>
>>>POJO Shark is library, so it won't open a new thread to execute process.
>>>If your tool-agent says sleep 20sec Shark will obey, and your
>>>application will too, that's why these process instances were executed 
>>>in sequence :-)
>>>
>>>To make it *really* parallel let your application start a new Thread for
>>>those 5 instances, or use Scheduler tool-agent in your xpdl (like
>>>test-Scheduler.xpdl).
>>
>>
>>hope this helps
> 
> 
> 
> 
>
message-footer.txt (text/plain, 271 B)
--
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws