• Post Reply Bookmark Topic Watch Topic
  • New Topic

'thread-safe' and 'synchronized'

 
kenji kunoichi
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is threadSafe and what is synchonised ?


 
Campbell Ritchie
Marshal
Posts: 52516
118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Synchronized is a keyword which prevents access to a particular block of code from two threads; it makes it behave as if it were atomic, ie rather like a single-stage procedure. Only one thread can gain access at a time.

Thread safe is a common English description for an object which cannot suffer any problems because of access by two threads at the same time.

Go through the Java Tutorial about concurrency. The Tutorial is required reading!
 
shankar reddy
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ThreadSafe can get by using Syncronization. When the Object should be accessed only one request at a time , we can use syncronization.
 
Campbell Ritchie
Marshal
Posts: 52516
118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are other ways than synchronisation to make an object thread-safe, eg locking, or an immutable class.
 
amitabh mehra
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Campbell Ritchie:
There are other ways than synchronisation to make an object thread-safe, eg locking, or an immutable class.


found a link regarding thread safety by immutable class:
Are Immutable class thread safe
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!