• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to invoke method recursively for every 5 minutes at server side

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Every One

Iam new to this site


User requests to generate report in browser then server gives reply after few minutes mean while i need to check is browser opened or not for every 1 min .if browser closes then session should get stop ie i need to stop running thread .Problem is how to invoke a process or method for every 1 minute.
Iam using servlet concept here i can check with session ids and last accessed time but how to call method for every 1 min i need to check is browser opened or not reglarly until procees is over.

If we use threads concept how to re call a method .


Just suggest me to overcome this problem

Plz Help Me Soon its urgent and sorry for my englisg

Have a Nice Day

Regards,
BhavyaRaj
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
bhavya raj,

Welcome to JavaRanch.
Don't worry about your English. It's much better than my (name a language)...
If you can, however, we would appreciate it if you would spell words out completely ('Plz' is not a word. Use 'please'). Contractions such as 'plz' or 'u r' instead of 'you are' confound language translation software and make it difficult for folks without your english speaking abilities to read your posts.

When dealing with long running processes, it's a good idea not to count on the user keeping their browser open while the process runs. Some browsers will time out on the user leaving them disconnected from what the server is doing.

Two common approaches are to:
1.) Let the user kick off the process, return them immediately to a message screen, and then have the back end send them an email when the process has completed.

2.) Let the user kick off the process, return them immediately to a screen that refreshes (using a meta refresh tag or javascript). Each time the page refreshes, it can check on the status of the server side process. If the process is done, forward them to a page that will allow them to retrieve the report, else, keep forwarding them to the refreshing status page.

I have an example of the second approach on my site.
http://simple.souther.us/not-so-simple.html
Look for "Long Running Process"
[ May 18, 2006: Message edited by: Ben Souther ]
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Possibly you can also use Ajax. For this, javascript must be enabled.
You can use setTimeout() function in javascript and repeatidely call a javascript function which fires XMLHttpRequest to the servlet.

Might be this helps.
 
bhavya raj
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for ur reply

Following war working properly

http://simple.souther.us/not-so-simple.html
Look for "Long Running Process"

When iam closing browser before 30minutes the session is getting invalidated but thread is running upto 30sec.

for that i wrote stopProcess method in ProceessSimulator class
as follows

public void stopProcess()
{
try{
Thread t1= Thread.currentThread();
System.out.println(t1.isAlive());
t1.destroy();
System.out.println(t1.isAlive());
System.out.println("This in stop process method");
}catch(Exception e){
e.printStackTrace();
}

}

When i close browser where sholuld i check seeeion id in servlet and where sholuld i invoke a method to stop thread ?

Aim is to stop the thread when i close browser.Means if browser closed at 15sec even thread should get stop at same time.

Regards
Bhavya Raj
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the server, you can't know if the user has closed the browser or not.

If the process is to last a very long time, the user may want to close the browser and come back later.
In the example I gave you, the process is bound to session for simplicity's sake but in a real world app, you might want to find another way to map it to this user so that s/he can log out, log back in later and see how the progress is going and/or retrieve the results if it is done.
Also, if this app requires a valid login, then you will probably have access to the user's email address which means that you can fire off an email when it's done. This way your user doesn't need to sit and wait for it to finish.
 
reply
    Bookmark Topic Watch Topic
  • New Topic