aspose file tools
The moose likes Threads and Synchronization and the fly likes Are static methods that don't use class variables safe? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Are static methods that don Watch "Are static methods that don New topic
Author

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

bengt hammarlund
Ranch Hand

Joined: Oct 17, 2003
Posts: 78
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!


<b><i>Bengt Hammarlund</i><br />� Sun Certified Java Programmer</b>
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Are static methods that don't use class variables safe?
 
Similar Threads
Thread interrupt confusion
doubt on Threads
Multiple threads and local members
when extend a class
Threads Doubt