Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static method

 
Paul Medford
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a doubt now...
Say you have a util abstract class with static methods. Whenever a method is called, is it thread safe? or is there a chance that the same method be called more than once at the same time and corrupting the data?
Simple question, but I'm kind of puzzled...
Thanks,
Francois
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Francois,
The only way to make a method thread safe is to make the methods synchronized.
Example (thread safe ):
java.util.Vector
Example (not thread safe):
ArrayList
Regards,
Manfred.
 
Junilu Lacar
Bartender
Pie
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or make sure that you only access local variables in it and not access any instance or class variables.
Junilu
 
Paul Medford
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, it's what I thought. I just had a doubt, somehow...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic