This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

thread safe classes...

 
Chetan Dodiya
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is thread safe???
when a class is said to be thread safe???
 
Brian Legg
Ranch Hand
Posts: 488
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread safe means that a piece of code can only be accessed by one Thread at a time. This uses the synchronized keyword.

If a class is said to be "thread safe" it means that all the methods in that class are synchronized, or again, can only be accessed by one Thread at a time.

Search on multithreading and synchronization for more information.

EDIT: Remember that a class can not be defined as synchronized, just the methods in the class.
[ November 12, 2008: Message edited by: Brian Legg ]
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread safe means that a piece of code can only be accessed by one Thread at a time. This uses the synchronized keyword.


I am not sure if I agree with this... IMO, Thread Safe means that the class can be accessed by multiple threads, and it will still work as documented. It could be achieved by synchronization. It could be achieved by segmenting data. It could be achieved by optimistic locking. It could even be achieved by documenting that it will throw an exception condition, under certain situations.

Henry
 
Brian Legg
Ranch Hand
Posts: 488
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll have to concede to the man who wrote the book on threads.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic