dcsimg
Help needed in Background processing of threads
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   yugandhar_yandapalli
Posted On:   Wednesday, May 1, 2002 10:52 PM

I have a method in a java file which will do some processing.


I want to call this method in a background process.
i.e. i have a web based application. The users will click a button in a page,where this method is called and will do the background processing. while this processing is going on , the user will navigate to the other pages of the application.


I will notify the user by mail once this process is completed.


Can anyone guide me with an example.
Thanks in advance.

Re: Help needed in Background processing of threads

Posted By:   Christopher_Koenigsberg  
Posted On:   Thursday, May 2, 2002 08:08 AM

Put it in the servlet context ("application scope") instead of in the session context, and then it will live on after the user's session is terminated.

Re: Help needed in Background processing of threads

Posted By:   bharani_iyer  
Posted On:   Thursday, May 2, 2002 01:12 AM

Hello Yugandhar,

Create a class BkgrJob which implements the Runnable interface.


public class BkgrJob implements Runnable {


private methodProc() {

//do processing...

sendEmail();

}



private sendEmail() {

//...

}


public void run() {

methodProc();

}

}

Now from your GUI class, On button clicked instantiate a new BkgrJob object and invoke start() method as follows :

BkgrJob theObj = new BkgrJob();

theObj.start();

This would do the necessary background processing in a separate thread, while in the main thread the user could perform other navigation related activites.


Cheers,

bharani.

About | Sitemap | Contact