Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Concurrent calls to static methods  RSS feed

 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a static method that does hold variables within the method, but holds on to no state from the Class it is in, does that method need to be synchronized?

example:


Of course the two private methods would do more than just return the value.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope, you're in a safe place because each thread gets its own copy of the local variables in the methods. You're in danger when two threads can get references to the same object, which could, unbeknownst to you, happen with your argument!
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I thought that was fine, but I'd prefer bounce that off of somebody else rather than have to debug odd race conditions later.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Steven Bell:
. . . rather than have to debug odd race conditions later.
Awww, but those are soooo fun!
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Threads and Synchronization...
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!