Page 832 - Introduction to Programming with Java: A Problem Solving Approach
P. 832
798 Appendix 9 Multithreading
/*************************************************************
*
Predator.java
Dean & Dean
This models predators (consumers), who desire encounters.
*************************************************************/
*
*
*
public class Predator extends Thread
{
}
// end Predator class
// delay times in milliseconds
public final long[] DELAY = {2347, 1325, 1266, 3534};
private Encounter encounter;
//**********************************************************
public Predator ()
{
super ("predator");
} // end constructor
//**********************************************************
public void setEncounter(Encounter encounter)
Apago PDF Enhancer
this.encounter = encounter;
} // end setEncounter
{
//**********************************************************
public void run()
{
}
// end run
int i;
for (i=0; i<DELAY.length; i++)
{
}
try
{
}
Thread.sleep(DELAY[i]);
// rest & hunt
// eat prey
catch (Exception e) { }
encounter.beTogether();
System.out.println(getName() + " run finished.");
Figure A9.3 Class describing a predator (consumer) which seeks prey This is driven by the class in Figure A9.1.