This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is JSP thread safe?

 
Shruti Sharma
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I understand that servlet is multithreaded and not thread safe. How about a JSP? Is JSP thread safe by default?

The JSP page directive isThreadSafe is true by default which means that JSP should be thread safe. But every JSP gets translated to a servlet, so that should mean that JSP is not thread-safe. Is it not contradictory? I am confused about this concept.
Please help.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Ss Sharma", please check your private messages for an important administrative matter. Again.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ss Sharma wrote:Is JSP thread safe by default?

As asked, this question makes no sense. It's like asking "Are Java methods thread safe?"

And the answer is "It depends what you do in them."

The JSP page directive isThreadSafe is true by default which means that JSP should be thread safe.

That directive does not make a JSP thread-safe. It's meant for you to tell the JSP engine whether the JSP is thread-safe or not.

If you use Java scriptlets in a JSP ( in 2010? I would hope not!) it's easy to make a JSP non-thread-safe. Especially if you use scriptlet declarations (Again, ).

Also, modifying values stored in the session and application scopes can create thread-safety issues.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic