Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread Safe access

 
Vijay Kashyap
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have heard people talking about creating only local variables in doPost,doGet methods for Thread Safe access. In some situations I need to call other methods from doPost, but beacuse of thread safty concerns I am passing all the variables to the called methods.
Like for instance in doPost

Is there any way to make vector accessible to other methods without passing as one of the input parameters and comprimising Thread Safety ? I know I can implement SingleThreadModel but I am looking if there is any other way I can do it.
Regards,
Vijay
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can synchronize access to those variables.

But there's also nothing wrong with your approach either.
 
SAFROLE YUTANI
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the method that you indicated. An alternative would be to synchronize the method, but this may produce a negative impact on performance. There is absolutely nothing wrong with your approach. You should always try to use automatic (local) variables when using servlets.
good luck,
SAF
 
Gerry Giese
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does one do when all copies of a running servlet need to know and update a set or list of values? What modifiers are on the variables, and how is the best method to synchronize it to keep the updates safe? For example, doing writes to a data or log file?
Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic