FileDocCategorySizeDatePackage
TestThread.javaAPI DocExample1710Thu Nov 08 00:22:50 GMT 2001com.ora.rmibook.chapter13.bank.applications

TestThread

public class TestThread extends Thread

Fields Summary
private static final int
MILLISECONDS_TO_PAUSE
private static int
_idNumberCounter
private NameRepository
_nameRepository
private TestResultHolder
_testResultHolder
private int
_numberOfOperationsLeft
private TestAppFrame
_owner
private String
_idNumber
Constructors Summary
public TestThread(NameRepository nameRepository, int numberOfOperations, TestResultHolder testResultHolder, TestAppFrame owner)


        
            
        _testResultHolder = testResultHolder;
        _nameRepository = nameRepository;
        _numberOfOperationsLeft = numberOfOperations;
        _owner = owner;
        _idNumber = String.valueOf(_idNumberCounter++);
    
Methods Summary
private TestgetRandomTest()

        double choice = Math.random();

        if (choice < .1) {
            return new GetBalance(_nameRepository);
        }
        if (choice < .6) {
            return new MakeDeposit(_nameRepository);
        }
        return new MakeWithdrawal(_nameRepository);
    
public voidrun()

        while (_numberOfOperationsLeft > 0) {
            Test testToPerform = getRandomTest();

            testToPerform.performTest(_idNumber);
            _testResultHolder.addResult(testToPerform);
            try {
                Thread.sleep(MILLISECONDS_TO_PAUSE);
            } catch (Exception ignored) {
            }
            _numberOfOperationsLeft--;
        }
        _owner.testThreadFinished(this);