Lab05 Hints and Tips
Part 1
-
In Step 3, the inner class should look like:
private static class StockTickerThread extends Thread
{
private String symbol;
public StockTickerThread(String symbol)
{
this.symbol = symbol;
}
public void run()
{
}
}
In Step 4b, use code like:
Random rand = new Random();
int sleep = r.nextInt(5000);
try
{
TimeUnit.MILLISECONDS.sleep(sleep);
}
catch (InterruptedException e)
{
System.out.println("Thread interrupted");
}
In Step 5a, use code like:
StockTickerThread t1 = new StockTickerThread("IBM");
StockTickerThread t2 = new StockTickerThread("Microsoft");
In Step 7c, your loop might look like:
while (cancel == false)
{
. . .
}
Part 2