wood burning stoves 2.0*
The moose likes JSP and the fly likes Long request with struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Long request with struts2" Watch "Long request with struts2" New topic
Author

Long request with struts2

eddy johns
Ranch Hand

Joined: Feb 16, 2010
Posts: 67
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

Joined: Feb 16, 2010
Posts: 67
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

Joined: Jul 14, 2010
Posts: 754

That depends on your containner. Which one are you using?


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
eddy johns
Ranch Hand

Joined: Feb 16, 2010
Posts: 67
Eclipse & Tomcat 7.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60740
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
eddy johns
Ranch Hand

Joined: Feb 16, 2010
Posts: 67
Thanks, Bear.
eddy johns
Ranch Hand

Joined: Feb 16, 2010
Posts: 67
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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".)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Long request with struts2
 
Similar Threads
I don't think we've congratulated Sharon Ross yet...
regarding interview pattern in UK
Are there any tools for Process?
Process ID?
.NET dataset in java