Semaphore - Example Of Semaphore Locking In Java To execute...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Example Of Semaphore Locking In Java To execute this set of applications, type "java DataBaseSemaphore" in the C:\AdvJava\ new_labs\Examples directory. The Lock /** This class provides the semaphore for the "data base" * (or any resource that must limit access to a single thread * at a time). This class does not do the locking - it simply * provides the common object that applications use as the "lock" * to restrict their access to the resource. (The address of the * lock object is placed in static so it is easily available.) * As with C programs, all applications using the resource must * restrict their access by placeing their processing code in a * synchronized block. If any application fails to "play the game", * the data integrity of the resource is exposed. */ public class DataBaseSemaphore { public final static Object lock = new Object(); // the lock! } The Application Starter /** This class starts the applications that use the "data base". */ public class DataBaseStarter
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/25/2010 for the course ECE 309 taught by Professor Bowman during the Spring '09 term at N.C. State.

Page1 / 2

Semaphore - Example Of Semaphore Locking In Java To execute...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online