File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes JSP with Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP with Threads" Watch "JSP with Threads" New topic
Author

JSP with Threads

NitinJ Gupta
Greenhorn

Joined: Jun 03, 2004
Posts: 4
Hi All,
I am facing a complex situation in which I would like to have your advice.
I am programming a web application where the situation is while processing I need to get user inputs i.e I perform some actions and prompt the user for further processing.Depending on user input I continue with the process transfer control to some other method or stop processing.I cant transfer control again and again between my JSPS and servlets as at the begining of the process I retrieve lots of data and store them in objects also there r many methods to be executed so it would require maintaining many flags and doing the situation accordingly.
There can be two solns for this
Either use applets for user prompting
Use Threads.
Prob with applets is that they may not run on all platforms and platform independence is our main issue.
With threading it can be done as follows.
The execution will begin in a thread.We will maintain an object in session which both the JSP as well as the Thread will access. Thread will do some processing and wait whenever it requires user inputs.At the user side the JSP will be continuously refreshing taking the object from session and will display dialog boxes whenever reqd , update the session object and wake the thread.This way the purpose can be achieved.
I am not very sure if there is a better way of solving this problem
So I would like to have ur advice on this.
Thanks
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Basically, you've got a design problem. Your web application is no more complex than anyone else's, and all these problems have been solved nicely already -- you just need to learn how it's done.

Very briefly, JSPs and Servlets have a Context available to them in which they can store objects. Take all your logic out of the JSPs, and put it into plain old Java objects (POJOs) and store these objects in the session context. Use the JSPs only for presenting the GUI. The POJOs retain their state in between calls.

I'm moving this to the JSP forum where there will be plenty of folks to back me up -- this really has nothing to do with Threads.


[Jess in Action][AskingGoodQuestions]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

Consider Ernest backed up.

If your application cannot be achieved using existing servlet/JSP technology and established best-practice patterns which are layered upon the request/response cycle of the HTTP protocol, perhaps it is not the appropriate technology for the application. You might need to consider a fat-client, network-enabled Swing application.

I'd suggest reading up on web application architecture before diving off into weird solutions like trying to thread a web app.
[ June 03, 2004: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ken Januski
Ranch Hand

Joined: Aug 08, 2002
Posts: 130
POJO! Well that's a new one. Best sign a book contract before someone beats you to it, POJO: Best Practices, or something like that.
David Hibbs
Ranch Hand

Joined: Dec 19, 2002
Posts: 374
Keep in mind that under J2EE 1.4 you won't be able to start a thread in a JSP/servlet (so long as the container complies to the spec, anyway). The right way to do this is to use a Message Driven Bean (MDB).
See the following article--right here on the ranch, by our pardner Kyle Brown.

http://www.javaranch.com/newsletter/200403/Journal200403.jsp#a4


"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP with Threads
 
Similar Threads
Please help Newbie
How Would YOU Architect This?
running a process in background (in separate thread)
Facades, Entity Beans and DAOs
Reading an ArrayList from JSP to Servlet