01: /**
02:    A withdraw thread makes periodic withdrawals from a bank account.
03: */
04: class WithdrawThread extends Thread
05: {
06:    /**
07:       Constructs a withdraw thread.
08:       @param anAccount the account from which to withdraw money
09:       @anAmount the amount to withdraw in each repetition
10:    */
11:    public WithdrawThread(BankAccount anAccount, double anAmount)
12:    {
13:       account = anAccount;
14:       amount = anAmount;
15:    }
16: 
17:    public void run()
18:    {
19:       try
20:       {
21:          for (int i = 1; i <= REPETITIONS && !isInterrupted(); i++)
22:          {
23:             account.withdraw(amount);
24:             sleep(DELAY);         
25:          }
26:       }
27:       catch (InterruptedException exception)
28:       {
29:       }
30:    }
31: 
32:    private BankAccount account;
33:    private double amount;
34: 
35:    private static final int REPETITIONS = 10;
36:    private static final int DELAY = 10;
37: }
38: