Transcript

This is the simplest application we can write.

What will it require in the way of threads?

* Thread main

* Thread “Reference Handler (system thread)

* Basic JFrame

* Still have our main thread

* Still have our system thread “Reference Handler”

* Notice, the main thread has expired.

* The other threads remain until the GUI expires.

* Basic class that implements a single thread

* No main method--just a class

* Reusing our BasicApplication

* Will instantiate one additional thread

* Have instantiated new object sal but have not yet created a new thread.

* Thread main has died, but the application lives on until the last thread is dead.

* Now will have two new threads in addition to main

* Thread main has expired. But, because of breakpoints, the

two other threads are still alive.

The Tortoise Versus

the Hare: Example

First, Tortoise and Hare each must extend

Thread

You do not need to get

this fancy in how you move your Tortoise

or Hare

You only need to use the Thread method ‘sleep()’

You instantiate Race3 and then call its ‘go()’ method.

‘go()’ just instantiates Hare and Tortoise and calls their start() methods.

top related