Threads Section Index | Page 6
What is the difference between multithreading and multitasking? What about multiprogramming? Multiprocessing?
Multitasking is running multiple "heavyweight" processes (tasks) by a single OS.
Multithreading is running multiple "lightweight" processes (threads of execution) in a single ...more
When exactly is the AWT thread started?
Anytime the java.awt.Toolkit instance is (directly or indirectly) created. The direct way to create it is by calling-
Toolkit.getDefaultToolkit();
Indrect way is by creating any AWT object.
Her...more
Does the main thread get terminated after returning from main(), even after spawning one or more threads?
Yes. You can determine this by running the following program and doing a thread dump:
public class mainthread extends Thread
{
public static void main(String[] args)
{
mainthread ...more
What is InterruptedException? Why do we need to catch it when calling Thread.sleep()?
InterruptedException is thrown if another thread calls interrupt() on the sleeping thread while it is asleep. If sleep() is setting an alarm clock before bed, interrupt() is a midnight phone call...more
What is the mechanism of Thread Priority & Thread Scheduler? How do Threads with various priority levels behave in time-sliced and non-time-sliced environments?
Mapping of Java's 10 thread priorities to the underlying OS is platform dependent. For example, NT has 7 priorities which needs to get mapped to Java's 10 -- and you don't really know what Java p...more
What threads are initialized when you start an application? (I heard six. What do they do?)
Theres an easy way to list the threads running in a JVM, just write the following class, compile and run from the command line....
public class ThreadDisplayer
{
public static void main( Stri...more
Is there a limit to the number of threads that can be spawned in a program?
There is no technical limit. There are theoretical limits that a platform can support. If you look at the Volano report, you'll see some limitations that they ran across.more
What is deadlock? How can I eliminate it?
A simple deadlock situation is one in which a two threads are waiting. Each thread waiting for a resource which is held by the other waiting thread. [In Java, this resource is usually the object ...more
Is there a way in Java to check whether an object is locked (i.e. some thread has it) in a non-blocking fashion?
Is there a way in Java to check whether an object is locked
(i.e. some thread has it) in a non-blocking fashion?
Is there an atomic operation that would get the lock
if it's available and bail imme...more
When and why is IllegalMonitorStateException thrown?
According to the JavaDoc, IllegalMonitorStateException is thrown "to indicate that a thread has attempted to wait on an object's monitor or to notify other threads waiting on an object's moni...more
What is the difference between threads and interrupts ?
A thread is a CPU's state of execution as it processes a set of instructions (also referred to as a task). An interrupt is a condition that causes the CPU to store the state of its current thread...more
How do you write a Thread-Safe Singleton?
I have written plenty of non-thread-safe Singletons but it wasn't until recently when I tracked it down that I realized that thread-safety could be a big problem.
The problem is that in the typic...more
What is the difference between a thread and a process?
A process is an OS-level task or service. A thread runs "inside" a process and may be virtual or simulated. Generally speaking, threads share resources like memory, where processes each ...more
How does one read a thread dump? (Especially the first line, '"47" (TID:0x1780818, sys_thread_t:0x9b4780, state:CW, native ID:0xd4) prio=5', and the Monitor Cache Dump.)
This article has the answers to all of your questions.
http://developer.java.sun.com/developer/technicalArticles/Programming/Stacktrace/index.html
-Joel
more
What is the historical context of Java's thread model? For example, what's a monitor?
Java programmers sometimes hear that Java's mutual exclusion mechanism is
based upon monitors. Here, I give the historical context for Java's thread model and define monitor.
In the mid-1960's...more