Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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
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
It's not a secret anymore!