Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
- What method in
Timer
orTimerTask
can you use to determine when the task was most recently scheduled to execute? (Hint: You can find the answer by looking at the API documentation forTimer
andTimerTask
. Remember that these classes were introduced in version 1.3 of the Java platform.)
- What is the effect of calling the
start
method on aThread
object?
- What are the two ways you can provide the implementation for a thread’s
run
method?
Check your answers.
- Convert
so that the initial delay is 5 seconds, instead of 0.
AnnoyingBeep.java
- Convert
to use the
AnnoyingBeep.java
scheduleAtFixedRate
method instead ofschedule
to schedule the task. Change the implementation of therun
method so that if therun
method is called too late for a warning beep (say, more than 5 milliseconds after it was scheduled to run), nothing happens--no beep and string are generated. (Hint: Remember your answer to question 1.)
- Change the main program of
so that it creates a third thread, named "Bora Bora". Compile and run the program again. Note that you will also need
TwoThreadsTest.java
. Does this change your vacation destiny?
SimpleThread.java
- Compile and run
and
RaceTest.java
on your computer. Do you have a time-sliced system?
SelfishRunner.java
- Well-behaved threads voluntarily relinquish the CPU periodically and give other threads an opportunity to run. Rewrite the
class to be a
SelfishRunner
PoliteRunner
. Be sure to modify the main program into create
RaceTest.java
PoliteRunner
s instead ofSelfishRunner
s.
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.