• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

making a JSP page Thread safe

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How will I make session variables thread safe in a JSP page?
and How can I create a method in a JSP page. Is it possible? If yes then pls let me know?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One trick is to move all the code out of your servlet into a threadsafe class:

WorkerClass is not shared by multiple threads the way Servlet is, so it can use member variables. The vendor framework I'm using now does this. There is essentially one servlet that gets the right worker class for the request from a factory.


What's the downside? They must have designed servlets the way they are for some reason. The servlet design - one instance shared by many threads - reduces object creation and destruction. This trick guarantees one object created per request. How much does that matter? Anybody know? Any other pros & cons?

Editing - I just noticed you asked JSP and I answered Servlet. I haven't written enough JSP to know just how much the difference matters ... waddya think?
[ July 19, 2004: Message edited by: Stan James ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

How will I make session variables thread safe in a JSP page?
and How can I create a method in a JSP page. Is it possible?


Variables held in a session are isolated from all other user sessions - the only time that they are not completely thread safe is if you are processing multiple requests from the same user at the "same time" -as might occur with a frameset.
For creating a method in a JSP, I recommend you read a good tutorial on JSP. Here is a good place to start. I recommend the JSP "Reference Card" - very handy.
Bill
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't use JSPs for anything except displaying information, do all the rest in servlets.

How often does that mantra need to be repeated?
Why did Sun ever include the capability for scriptlets in the JSP spec?
Why do people keep posting JSP questions in the servlet forum?
[ July 20, 2004: Message edited by: Jeroen Wenting ]
 
It's never done THAT before. Explain it to me tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic