Threads Section Index | Page 9
What are the differences between extending the Thread class and implementing the Runnable interface?
Extending the Thread class will make your class unable to extend other classes, because of the single inheritence feature in JAVA. However, this will give you a simpler code structure. If you impl...more
The lowest level preemptive scheduler (kernel layer) uses the system timer interrupt and context switching to manage timeslices. When any CPU interrupt occurs, the CPU makes a note of where it wa...more
A preemptive scheduler interrupts a thread of execution when its timeslice runs out. A non-preemptive (or "cooperative") scheduler waits for the thread to yield control. [Java native t...more
Doug Lea has produced a utility library in conjunction with his Concurrent Programming in Java that includes many common classes needed to help you synchronize your data access, like mutex and sem...more
The thread's join() method allows you to wait for another thread to finish execution. Thread t1 = new Thread(runnable); t1.start(); // do stuff ... // wait for t1 to finish t1.join() more
Static synchronized methods synchronize on the class object (this.getClass()) of the class.
Non-static synchronized methods synchronize on the instance (this) of the class.
The static sleep() method of the Thread class will let your thread sleep for a set number of milliseconds (or nanoseconds). When the thread wakes up, it will be scheduled to execute in the future....more
Creating a thread involves creating a new Thread and invoking its start() method. Calling start() causes the run() method of the Thread subclass or the Runnable object passed to the Thread constru...more
A thread is a set of instructions executing apart from other threads (with its own stack) but sharing the same memory space (with the same heap).
Every thread of execution on any given platform has its own context, which contains an execution state, and a set of access rights (among other things). A thread's access rights are equal to tha...more
The Java 1.2 release introduced the concept of thread local variables as a standard class. Previously, they existed in the sun.server.util package of the Java WebServer product. Now, you get them ...more
It depends upon your needs. The O'Reilly Java Threads book is a great book for teaching about using the API. Doug Lea's book, Concurrent Programming in Java discusses how to properly design your p...more
Check out Doug Lea's concurrent programming package. more
You need to create the secondary threads in a custom ThreadGroup. Subclass ThreadGroup and override public void uncaughtException(Thread source, Throwable throwable). This method would then be not...more