aspose file tools*
The moose likes Java in General and the fly likes static methods and thread safety Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "static methods and thread safety" Watch "static methods and thread safety" New topic
Author

static methods and thread safety

Swapnil Dharane
Ranch Hand

Joined: Apr 22, 2012
Posts: 31
Hi all
Can you please tell me whether static mehods/variables are thread safe? if not why not?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13869
    
  10

There's nothing about static methods or variables that makes them inherently thread-safe.

You can easily write some example code with two threads, in which the threads try to write to the same static variable at the same time, so that the end result is unpredictable - which demonstrates that it's not thread-safe.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static methods and thread safety
 
Similar Threads
Message doesnt display continuously
Still Static Methods...
Static variable
Static Variable in Servlet
Mock Question about thread-safe