13_Review Lecture

If task 2 starts to enter the method and task 1 is

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: am, known as critical region. •  The critical region in the Account example is the entire deposit method. Locks •  You can use the synchronized keyword to synchronize the method so that only one thread can access the method at a time. o •  One approach is to make Account thread-safe by adding the synchronized keyword in the deposit method in Line 45 as follows: public synchronized void deposit(double amount) 33 Cri4cal Regions and Locks •  Used to be a topic of systems programming. Now a common topic •  The concept of cri4cal regions and locks are everywhere around us –  Share road outside of our academic building •  Lock Traffic light; CR Road –  Shared washroom of a coffee shop •  Lock Physical lock; CR The toilet •  In Java, every object is also a lock 34 Synchronizing Instance Methods and Static Methods •  A synchronized method acquires...
View Full Document

Ask a homework question - tutors are online