File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes multithreading in struts... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "multithreading in struts..." Watch "multithreading in struts..." New topic

multithreading in struts...

ritu gaur

Joined: Sep 12, 2005
Posts: 4
I am using struts and velocity for front end. I want to forward request to my web page which shows the progress bar and at the same time in the background some other process is going on. As soon as this process completes progress bar disappear and the msg returned by this process is displayed. I tried multithreading but
return mapping.findForward("success") returns and I am not able to get values from the previous thread in which batch process is going on.

How to do this thing.
Jayesh Lalwani
Ranch Hand

Joined: Nov 05, 2004
Posts: 502
Your struts action is going to run in the web server's thread, and the web server is going to start a thread for every requst. So, you have to start a thread that runs the background process. If you have to show the progress in the web page you can redirect to an Action that checks the progress and forwards to a jsp that shows progress. That jsp should set a imeout and rediect the user back to the checkProgressAction.

Something like this

Here, "done" goes to a page that displays "done" message. showProgress should go to a page that displays the progress bar. The showProgress should set a timeout that will redirect to the CheckProgress action after a second or so
Jacob Sonia
Ranch Hand

Joined: Jun 28, 2009
Posts: 179
How can i set this timeout in my view so that after every 1 second it goes to checkprogress and then returns back with the status
bhavani evuri

Joined: Jul 22, 2009
Posts: 8
Struts 1 Actions are singletons therefore they must be thread-safe because only one instance of a class handles all the requests for that Action. The singleton strategy restricts to Struts 1 Actions and requires extra care to make the action resources thread safe or synchronized while developing an application.

Struts 2 doesn't have thread-safety issues as Action objects are instantiated for each request. A servlet container generates many throw-away objects per request, and one more object does not impose a performance penalty or impact garbage collection.

if want any information just follow the below link
I agree. Here's the link:
subject: multithreading in struts...
jQuery in Action, 3rd edition