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
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: 36
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: 14111
    
  16

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