Threads are an integral to the Java language. If you remember, a paint() method is not invoked directly by the applet but by a thread in the interpreter. A thread is similar to a process but that multiple threads run in the same address space as the application. Multiple threads can be used to run different parts of your program simultaneously. If your computer does not have multi-processors then the threads really do not run concurrently. But the idea is that while the screen is waiting for some input some other process can be running. For instance, in Java the garbage collector thread runs in the background. Whenever the program is waiting on something, Java might invoke the garbage collector to free up space.
In Java, every thread begins by executing a run() method in a particular object. Run() is declared to be public, takes no arguments, has no return value, and is not allowed to throw any exceptions. Any class can implement a run() method by declaring that the class implements the Runnable interface.
Java also simplifies the synchronization of threads. The structures used for
this simplification is based on monitors, which is a popular scheme
developed by C.A.R. Hoare. A monitor is a lock that only one thread can
access at a time. If one thread holds the lock, then the other threads
must wait for that thread to finish in order to acquire the lock.