preview

Monitor In Java Essay

Decent Essays

Monitors in Java are an incredible tool for developers because it allows for multiple threads run through a single object without corrupting data. The monitor is a fundamental high-level synchronization method for Java because, since Java supports synchronization is through the monitor it allows for multithreading support at the language level (artima). In relation to class, in Java a monitor is simply an object which can be utilized for synchronization; however, a bit more can be elaborated on how monitors are implemented in Java. Normally when handling code synchronously, a locking and release mechanism will be required to notify when the critical section can be entered and in some languages the semaphore, or mutex, locks would need to …show more content…

Now even though this is an interesting way to handle synchronization in java, monitors offer quite a bit of personalization for programmers. One way to show how tailored a monitor can be is by examining a class to satisfy a monitor’s property of mutual exclusion. By observing the following code snippet written by Baptiste Wicht shows a class whose objects ensure mutual exclusion among the methods (baptiste). In Wicht’s example, he shows that it is rather straightforward to ensure the mutual exclusion property for monitors by locking the method the moment it is entered and then releasing it upon completion. However, if a programmer wishes to only exclude a critical sections smaller than an entire method without mutex locks, Java makes that rather straightforward to do by using an approach discussed previously called, synchronized statements. To do so, the critical simply needs to be wrapped up in a synchronized statement and this will ensure mutual exclusion. Lastly, condition variables, as described in lecture, are similar to a queued muted but has two differences in behavior. The first being the condition cannot be free as a mutex, waiting on a condition always waits, and signaling can only free a process already waiting. The second is that a thread waiting on a condition variable does not occupy the monitor. By taking this definition into account, it can be hard to find an implementation

Get Access