What is thread safety? How do you achieve it?

devquora
devquora

Posted On: Dec 28, 2020

 

Thread Safety refers to the way in which different threads can access the same resources without exposing erroneous behavior or producing unpredictable results.

Some different ways to achieve thread-safety are as follows.

  • Stateless Implementations
  • Immutable Implementations
  • Thread-Local Fields
  • Synchronized Collections
  • Concurrent Collections
  • Atomic Objects
  • Synchronized Methods
  • Synchronized Statements
  • Other Objects as a Lock
  • Volatile Fields
  • Reentrant Locks
  • Caveats
  • Read/Write Locks

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Java Interview Questions asked in Citibank

    Explain Multi-Threading in Java?

    It is a process in java through which multiple threads can be executed simultaneously. A thread can be explained as a lightweight sub-process, it is the smallest unit of processing. Both multiprocessi...

    Java Interview Questions asked in Citibank

    Explain the internal working of a hash map?

    In Java, A HashMap is a map used to store mappings or links of key-value pairs that works on the hashing principle. It is considered as a data structure that allows us to store objects and retrieve it...