What is the basic concept of synchronized keyword, is it responsible to our data integrity?
The key concept of synchronized keyword is locking the code to prevent other thread to access the critical code when one thread is processing it. You need acquire the monitor/lock from an object to lock it, and one object only has one lock/monitor. That is why when one thread acquired the lock/monitor, other threads have to wait. Why you need to lock the code? Mostly you need to keep the integrity of your data, and which is very application specific. The locking mechanism actually knows nothing about it. It is NOT responsible for your data integrity at all. It is you, the application programmer, who is responsible for it. For example, if you want to keep the integrity of your client’s bank account balance, you must synchronize all methods, which have access to and can change the balance. If you leave a loophole there, you probably will be fired by your boss, not Dr. Gosling or someone else who designed the locking mechanism. I just want to scare you… However, when you are synchronizi
Related Questions
- Is the cable modem safe to use as it is using a LAN concept? Is there any firewall on the server to protect data integrity even up to the level of individual modem units?
- What is the source of the WTE and birth data used to set each member’s basic contribution?
- Who is responsible for data integrity?