Threads Section Index | Page 2
How do I configure a default handler for exceptions that happen in all threads?
The setDefaultUncaughtExceptionHandler() method of Thread, introduced in JDK 5.0, allows you to configure this behavior by letting you attach an implementation of Thread.UncaughtExceptionHandler. more
How can I get the number of active Groups within a ThreadGroup?
ThreadGroups activeGroupCount() returns the number of active groups within the ThreadGroup instance it was called upon. Once the number of active groups is obtained ThreadGroups enumerate(ThreadG...more
What is a ThreadGroup?
A ThreadGroup is used to represent a group of Threads. A tree structure can be formed from ThreadsGroups containing other ThreadGroups. Threads can only access the ThreadGroup to which they belon...more
What is a ThreadGroup?
A ThreadGroup is used to represent a group of Threads. A tree structure can
be formed from ThreadsGroups containing other ThreadGroups. Threads can only access the ThreadGroup to which they belon...more
How can a Thread preempt another Thread?
Any Threads running within the JVM can be preempted by creating and starting a
Thread which is of a higher priority. A Threads priority can be set using the following method.
public void setPr...more
What is a Thread identifer and how can I obtain it?
A Threads identifer is a positive unique long value which is generated when a Thread is created. Using the following method a Threads identifer can be obtained.
public long getId()
Here is a ...more
Is there a way that I can get the number of threads currently executing within the JVM?
Is there a way that I can get the number of threads currently executing
within the JVM?
How can I tell the difference between wait(timeout) timing out and actually being notified?
You can't directly by using wait and notify, but the can use a similar construct with the Lock interface of the java.util.concurrent.locks package, with its boolean tryLock(long time, TimeUnit uni...more
How can I create a thread pool?
The Executors class of the java.util.concurrent class offers newCachedThreadPool(), newCachedThreadPool(ThreadFactory threadFactory), newFixedThreadPool(int nThreads), newFixedThreadPool(int nThre...more
What purpose does the TimeUnit class have?
The TimeUnit class allows you to work with time quanities as both an amount and a unit of measurement. For instance, instead of always working with milliseconds when you want to put a thread to sl...more
How can i tell what state a thread is in?
Prior to Java 5, isAlive() was commonly used to test a threads state.
If isAlive() returned false the thread was either new or terminated but there was simply no way to differentiate between the...more
How can I create a daemon thread?
The Thread API allows Threads to be created which are at the mercy of their user threads. This is accomplished simply by passing true to the setDaemon() method and invoking the method off an insta...more
How do I configure a default handler for exceptions that happen in my threads?
The setUncaughtExceptionHandler() method of Thread, introduced in JDK 5.0, allows you to configure this behavior by letting you attach an implementation of Thread.UncaughtExceptionHandler. The int...more
What happens if two threads perform a get of one hashmap at the same time?
[I know a HashMap object is not synchronized if not done explicitly, so in a case where you have to write and read data in a hashmap from different threads you need to synchronize it (or use anoth...more
Is it possible to wake up a sleeping thread?
[I have a thread which is sleeping for a long period of time.Another object has the object of this sleeping thread. In some event , the second object wants to wake up the sleeping thread before i...more