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.
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
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.