Oracle9i Supplied PL/SQL Packages and Types Reference Release 2 (9.2) Part Number A96612-01 |
|
DBMS_LOCK , 3 of 3
The following Pro*COBOL precompiler example shows how locks are used to ensure that there are no conflicts when multiple people need to access a single device. The DBMS_LOCK
package is used to ensure exclusive access.
Any cashier can issue a refund to a customer returning goods. Refunds under $50 are given in cash; anything above that is given by check. This code prints the check. One printer is opened by all the cashiers to avoid the overhead of opening and closing it for every check. Therefore, lines of output from multiple cashiers can become interleaved without exclusive access to the printer.
CHECK-PRINT
Get the lock "handle" for the printer lock:
MOVE "CHECKPRINT" TO LOCKNAME-ARR. MOVE 10 TO LOCKNAME-LEN. EXEC SQL EXECUTE BEGIN DBMS_LOCK.ALLOCATE_UNIQUE ( :LOCKNAME, :LOCKHANDLE ); END; END-EXEC.
Lock the printer in exclusive mode (default mode):
EXEC SQL EXECUTE BEGIN DBMS_LOCK.REQUEST ( :LOCKHANDLE ); END; END-EXEC.
We now have exclusive use of the printer, print the check:
...
Unlock the printer so other people can use it:
EXEC SQL EXECUTE BEGIN DBMS_LOCK.RELEASE ( :LOCKHANDLE ); END; END-EXEC.
|
Copyright © 2000, 2002 Oracle Corporation. All Rights Reserved. |
|