Class BobBank
java.lang.Object
BobBank
public class BobBank
- extends Object
This class shows how to synchronice a bunch of people who take money out
of the same bank account. Each person is called Bob[i]
.
- The
bankTeller
semaphore is used to make sure that only
one person has access to the shared account.
- The
reduce
semaphore is used to add up all the money taken by
each Bob[i]
to check that exactly the money that was initially
in the bank is the amount that was taken out by each Bob[i]
.
- Semaphore
reduce
is initialized using the number of Bobs
because each Bob[i]
needs to signal that they finished taking
money out of the bank before the money can be counted.
This is an example of Map/Reduce. In the "Map" face, in program "main()",
the syncrhonization semaphores are set up and the Bob task are created.
The "Reduce" face is executed after all the Bob processes are done; in this
face the amounts are totalized to verify that exactly the inital amount was
withdrawn from the bank.
Field Summary |
(package private) static int |
GaZillion
I have this much money. |
(package private) static int |
ManyBobs
A bunch of Bobs compete to drain the bank account. |
Method Summary |
static void |
main(String[] args)
Main program. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
GaZillion
static final int GaZillion
- I have this much money.
- See Also:
- Constant Field Values
ManyBobs
static final int ManyBobs
- A bunch of Bobs compete to drain the bank account.
- See Also:
- Constant Field Values
BobBank
public BobBank()
main
public static void main(String[] args)
- Main program.