| Chapter 16: Concurrent Programming with Java Threads |
|---|
| Source Code in This Chapter |
|---|
![]() |
|---|
| Order now |
Thread object.
Thread.
Thread and defines a run method that counts
up to a specified value, pausing for a random time interval in between value
counts.
Runnable interface while
providing a run method for thread execution.
Counter2) that count from 0 to 4.
In this case, the driver does not start the threads, as each thread is
automatically started in Counter2's constructor.
Uses the following class:
Runnable
that counts to a specified value and sleeps a random number of seconds
in between counts. Here, the thread is started automatically when
the object is instantiated.
RSAKey
computes an RSA public-private key pair, where the key size has a specified
number of digits.
As large prime numbers require considerable CPU time, ThreadedRSAKey
converts the original computeKey method in RSAKey to a
multi-threaded method, thus allowing simultaneous (multithreaded) computation of
multiple key pairs.
Uses the following classes:
repaint to schedule an update of the
display.
draw method to paint the circle on
the graphics object.
paint
method. The graphics object is obtained by calling getGraphics.
See Rubberband.html.
update to reduce animation
flickering and performing incremental updating in the
paint method. Here, to achieve
animation, a single thread continuously calls repaint
while subsequently sleeping for a 100 milliseconds.
See Bounce.html.
Uses the following classes:
SimpleCircle that can be moved
about and bounces off walls.
SimpleCircle that can be moved
about and bounces off walls.
Thread holding the images for the animation.
Timer.
Note that Timer is located in the javax.swing
package.
See TimedAnimation.html
(requires Netscape 6.x or a browser that supports Swing).
Uses the following classes and images:
| General |
|---|