Race condition never occurs in a thread-safe program. What is a race condition? When variables are shared by multiple threads, there is a possibility that more than one thread get access to a variable and try to modify its value at the same time. This could lead to a loss of data modification done by a thread and leave the program in an inconsitent state. Such hazards should be avoided by allowing only one thread to access the shared variables when they are being modified. Synchronized methods and synchronized blocks are used to lock […]