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

User Defined Thread in Action Class

Naresh Shaan

Joined: Mar 18, 2006
Posts: 22
am trying to do online examination application.

i have a action class which will pull questions from the database and display it to the user....

i made a userdefined thread, and started it and called sleep method in that for the exam duration....after the duration, the thread will forward the user to the results page!!!

i passed the request and responce objects in tha execute method to local variable and in the thread's run method, i tried to use them to initilize my Requestdispatcher object and called forward method...

the problem am facing is, just before i call the sleep method, when i try to print the request and response objects, its printing them..but once my thread resumes, both my request and responce variable are becoming null and am not able to forward my request to my results page...

i did a similar type of online examination before..and i had used javascript cookies...and in that case, java script code was responsible for chking time out and forwarding to the results page....

am trying to check for the time at the serverside now...

any other logic's would be gr8t ful

"The greatest pleasure in life is doing what people say you cannot do." - Walter Bagehot
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'm afraid that the way you're trying to do this simply won't work. You can't hold on to the request and response object in a separate thread. They're only good for the duration of one request, and as soon as the response is sent back to the browser, they're gone.

As an alternative, I'd suggest creating a timer Javabean that runs in a separate thread. Once you've started the timer, put this bean in session scope. When the time has expired, simply set a property on the bean (timeExpired = true). Then have each interaction with the server check the timer bean before performing any action (answer question, go back to previous question, etc.) If timeExpired is true, forward to the results page rather than performing the requested action.
[ January 03, 2007: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
Naresh Shaan

Joined: Mar 18, 2006
Posts: 22
thank you!!!
I agree. Here's the link:
subject: User Defined Thread in Action Class
It's not a secret anymore!