Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

thread safe

 
Gopal Krishna
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

how do i make our servelts are thread safe??

Regards,
Gopal
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gopal
Welcome to JavaRanch!

We're pleased to have you here with us in the servlets forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

You can change it here


Further, I can see that you've been asked at least twice before.
Please understand that accounts with invalid screen names are subject to being closed.
[ July 06, 2006: Message edited by: Ben Souther ]
 
Ash Kondhalkar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Implement Single thread model interface if you want to make your servlet thread safe. BUT BE CAUTIOUS, it makes performance of a servlet very slow. Until and unless its is unavoidable one should not go for Single Thread model.. The interface is available in javax.servlet package.
 
ak pillai
author
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SingleThreded model can adversely affect performance and hence depreceted as of spec 2.4.

You can synchronize on a block or method level where it is not thread-safe. Also can store your objects/ attributes in a session or database as opposed to as an instance variable in your servlet class.
 
Adam Asham
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also make your code thread safe by not using instance variables, for example. That is one step in the right direction.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic