I am having theoretical knowledge on Threads but i dont have much practical knowledge, when i am going through paymentgateway code of a eCommerce website i found two things
They have used volatile keyword for paymentStatus.
if we use volatile changes made by one thread will be visible to other thread. if we apply this to paymentStatus will override the paymentStatus if two threads (of two users) use this code at same time.
they have create a object for Object class and every time they modify the paymentStatus they are applying synchronization of this object
why do we need to apply synchronization on a Object class object which we are not using anywhere?