• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Long request with struts2

 
eddy johns
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I need to have a web interface with a button click that starts a process working several hours. I assume *something* will time out before the process ends. Is there a way to overcome it?

Thanks!
 
eddy johns
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, to be more specific, is there any way to stop the browser from timing out? Something like a struts object that keeps sending the browser a "stay alive" request of some sort?

Thanks!
Eddy
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends on your containner. Which one are you using?
 
eddy johns
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eclipse & Tomcat 7.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're best bet is to cause the long process to run in a separate thread and to return the response immediately. Have a way for users to come back later and check progress.

This has been discussed here before. Search for previous discussions.
 
eddy johns
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Bear.
 
eddy johns
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, wouldn't AJAX solve this problem, AND give the user feedback?

Can anyone point me to a good struts / ajax tutorial, with code that continually updates the client based on a long process running on the server?
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you could certainly use AJAX to implement "a way for users to come back later and check progress". You could also use a meta refresh tag in your HTML, though, so AJAX isn't the only way.

As for the tutorial, I'm sure you can find one but the concept isn't difficult.

The initial request starts a thread running and puts a reference to the thread, or to some proxy for the thread, into the user's session.

Subsequent requests get the thread from the session. If it is still alive, the response says "Still running", otherwise the response says "Finished".

Of course you can expand on this basic structure to return the result of the long-running process, or to return the percentage complete if the long-running process can produce that information. And if you expect the user to close the browser and come back several hours later, thereby in a new session, then you would have to store the reference to the thread in some place other than the session where it could be accessed based on the user ID or something like that. This would also be necessary if your server was distributed over multiple machines; the thread would be running on one machine, but requests processed by other machines in the cluster would need to find out about it. (That's why I said "proxy for the thread".)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic