Advanced Programing 2
Advanced Programing 2
Advanced Programing 2
Thread Scheduling
Creating a Thread
Synchronization
Both approaches still use the Thread class to instantiate, access, and control the
thread. The only difference is how a thread-enabled class is created.
The Runnable interface abstracts a unit of executable code. You can construct a
thread on any object that implements the Runnable interface. Runnable defines only
one method called run( ), which is declared like this: public void run( ) Inside run( ),
you will define the code that constitutes the new thread.
The sleep( ) method causes the thread from which it is called to suspend execution
for the specified period of milliseconds. Its general form is shown here: