What is MultiThreading?
Home ] Up ] [ What is MultiThreading? ] Threads & Thread Properties ] Thread Scheduling and Priority ] Types of Threads ] Monitors, Synchronization and Deadlocks ] Thread Coordination ] Communication Between Threads ] Threads and Thread Groups ] Explicit Locks ] Atomic Variables ] Blocking Queues ] Thread-Safe Collections ] Callables & Futures ] The Executor Framework ] Synchronizers ]

 

 

The ability to do (or appear to do) more than one thing at a time.

Every Java program is multithreaded, whether you write it to be that way, or not:

  • The AWT (and JEWT) rely on multithreading to do their work
  • There is always a garbage collector thread running in the background

The Java Virtual Machine is what implements and supports multithreading:

  • Most JVMs use the native operating system threads on whatever platform they run
  • Most machines only have a single CPU, and so multiple threads have to share the same CPU, and don't actually run concurrently -- they only give the illusion of concurrency.
  • Some machines have more than a single CPU, and native operating system threads can actually run concurrently.
  • Some JVMs have to implement their own threads, if the native platforms don't provide the necessary support.

Here are some bouncing ball demos:

A non-threaded bouncing ball demo.

Click the Start button to start bouncing a ball.
You'll notice that, once you've started a ball going, you can't start another ball until the first has finished.

A threaded bouncing ball demo:

By making the implementation multi-threaded, you'll find that the applet supports starting a number of balls concurrently. (Just click on the Start button multiple times.)
However, note that you can't start a ball in this applet until the applet on the left has finished bouncing balls.

Here's the source for this applet. Here's the source for this applet
 
The page was last updated February 19, 2008