• Post Reply Bookmark Topic Watch Topic
  • New Topic

Are static methods that don't use class variables safe?  RSS feed

 
bengt hammarlund
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a static method that only uses internal variables or variables that came as parameters on the function call, this function is thread safe?
I mean, these internal function values are stored in the calling thread's stack or other place?

Imagine this (useless) method:


and the calling thread's run() method:



Thanks in advance for any reply!
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, as long as you're not using any resources that might be shared by two threads - static member variables, other objects - you should be fine. I prefer not to talk about things like "stack space" but the idea that parameters and local variables in a method are in their own private space and scope is right & good.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!