Methods Summary |
---|
public float[] | getValues()
for (int i = 0; i < numThreads; i++) {
lookupThreads[i] = new Thread(this);
lookupThreads[i].start();
}
for (int i = 0; i < numThreads; i++) {
try {
lookupThreads[i].join();
} catch (InterruptedException iex) {}
}
return lookupValues;
|
private void | loopDoRange(int start, int end)
for (int i = start; i < end; i += 1) {
float sinValue = (float)Math.sin((i % 360)*Math.PI/180.0);
lookupValues[i] = sinValue * (float)i / 180.0f;
}
|
private synchronized javathreads.examples.ch15.example2.SinTable$SinTableRange | loopGetRange()
if (curLoop >= endLoop)
return null;
SinTableRange ret = new SinTableRange();
ret.start = curLoop;
curLoop += (endLoop-startLoop)/numThreads+1;
ret.end = (curLoop<endLoop)?curLoop:endLoop;
return ret;
|
public static void | main(java.lang.String[] args)
System.out.println("Starting Example 2 (Threaded Example)");
SinTable st = new SinTable();
float results[] = st.getValues();
System.out.println("Results: "+ results[0]+ ", "+
results[1]+ ", "+ results[2]+ ", "+ "...");
System.out.println("Done");
|
public void | run()
SinTableRange str;
while ((str = loopGetRange()) != null) {
loopDoRange(str.start, str.end);
}
|