Test Four Threads Running

This is part of JavaUnitTestChallengeSolved. -- DonWells


Now lets try four threads together:

 public class FourThreadsTogether extends Test {
    public BoundedBuffer buffer;
    public PutThread firstPutThread;
    public PutThread secondPutThread;
    public TakeThread firstTakeThread;
    public TakeThread secondTakeThread;

public void setUp(){ buffer = new BoundedBuffer(); firstPutThread = new PutThread(buffer); secondPutThread = new PutThread(buffer); firstTakeThread = new TakeThread(buffer); secondTakeThread = new TakeThread(buffer);}

public void runTest (){ TakeThread.resetOutput(); firstTakeThread.start(); secondTakeThread.start(); firstPutThread.start(); secondPutThread.start(); waitForTakeToFinish(); should(TakeThread.doesOuputHaveTwoOf("a"), "should get two a"); should(TakeThread.doesOuputHaveTwoOf("b"), "should get two b"); should(TakeThread.doesOuputHaveTwoOf("c"), "should get two c"); should(TakeThread.doesOuputHaveTwoOf("d"), "should get two d"); should(TakeThread.doesOuputHaveTwoOf("e"), "should get two e");}

public void waitForTakeToFinish(){ try { firstTakeThread.join(1000); secondTakeThread.join(1000);} catch (InterruptedException exception) {};} }

I was expecting problems of some sort with this one, but it runs just fine.


EditText of this page (last edited September 23, 2003) or FindPage with title or text search