Discussion

Spawning a background thread from online thread

Hi, We have a requirement to start a background process on a button click in a screen. User should be shown with a confirmation message with out having to wait for the process to complete. There are no WOs or flows involved in this process. It purely does some time consuming processing on the external database records. Basically I am trying to find out if there is any way to span batch thread from the online thread. Appeciate your suggestions Thanks

***Updated by moderator: Marissa to close post***
This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.

Comments

Keep up to date on this post and subscribe to comments

April 15, 2009 - 4:59am

call an activity when clicked on a custom button
branch xxxxxactivitynameXXX this will start a asynchronus thread
do your batch process in that xxx activity

April 17, 2009 - 2:40pm

Thanks for the reply. We have tried using Branch method to call the batch activity but that time thread spanning is not happening. Control is transferred to branch activity and as a reason we can not show the confirmation message to user.

Pega
April 17, 2009 - 2:50pm

Branch does not do asynchronous processing. As RAVULAS1 found, it's a procedural, single-thread, transfer of control to the invoked activity, so that after the invoked activity ends, it doesn't then continue executing the parent activity.

What version of PRPC are you using? In 5.4 and up, you may want to look at creating a Standard Agent and using the Queue-For-Agent method to dispatch the work to be processed in the background by an agent. There are many resources on PDN and PRPC Help on how to get started with those facilities.

Thanks.

- Tim (Pega)

April 17, 2009 - 6:11pm

Hi Tim,

We are using PRPC 5.4 Sp2. I have looked at the options suggested and they seem to be good. Our batch process will hardly be kicked off only 3 to 4 times a month. So we think there is no point in having an agent to wake up say for every 5 min and look at empty queue unnecessarily.

Is there a way to control the agent to wake up only when there is at least one object in the queue.

Thanks
Saidulu R

Pega
April 17, 2009 - 7:58pm

If the queue is almost always empty, there is very minimal overhead to have a Standard agent wake up and check the queue. Your activity will not execute if there are no items to process. The engine will efficiently check the queue for you and quickly go back to sleep once it discovers no new items to process.

But I understand your concern on having a background thread wakeup with your sparse usage pattern.

You can also schedule the agent to run on a recurring schedule, similar to an Outlook recurring calendar event. For instance, you can configure the agent to run every Friday night at 6pm, or weekdays at 5am, etc. If your application doesn't require the background processing to be spawned immediately after the user clicks the button, this may be an option for you.

April 22, 2009 - 7:32am

If you are using RDB- methods, you can click the "RunInParallel" option to start a executing the query in a separate requestor.

April 22, 2009 - 9:53am

Thanks for response. We are using RDB-method for calling a stored procedure and looked at the Run In parllel option. We can not catch the SP output and as a reason there is no way to track if the SP is executed successfully or not

April 29, 2009 - 4:48pm

We are going with AGENT to implement our requirement. I'll ping you in case if we ecncounter any issues. Thanks..