This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Thread Safe Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Thread Safe Objects" Watch "Thread Safe Objects" New topic

Thread Safe Objects

Rajeev Iyer
Ranch Hand

Joined: Jun 19, 2002
Posts: 42
Which are the thread safe objects in JSPs ?
Can a class variable (a static variable ) be thread safe?
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
In general, only "method" variables (declared in <% %> are definitively thread safe in JSPs.
Class ("static") variables are not. Object (instance) variables are not. Variables stored in application and session contexts are not. Variables stored in request or page contexts are probably thread safe, unless they are also one of the unsafe categories above.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Mani Narain

Joined: Dec 14, 2003
Posts: 4
To add...I guess the instance variables are thread safe if the JSP page has the directive (<%@ page isThreadSafe=false) is like JSP page implementing the SingleThreadModel...people correct me if I am wrong..

Joined: Jan 28, 2003
Posts: 4
Mani i hope you are correct .and in case of Single Threaded model static variables are not thread safe.
Patricia Johannes

Joined: Nov 08, 2003
Posts: 2
but singlethreaded model is defered in Servlet 2.4
I agree. Here's the link:
subject: Thread Safe Objects
Similar Threads
Static variable
Is session object thread safe.
can we assign a servletconfig object to global variable
Thread Safe
Static Variable in Servlet