Signals
Signals are the UNIX kernel's way of interrupting a running process and letting it know that
something of interest has happened. (NT has something similar but doesn't expose it in the Win32
interface.) It could be that a timer has expired, or that some I/O has completed, or that some other
process wants to communicate something.
Happily, Java does not use UNIX signals, so we may conveniently ignore them entirely! The role
that signals play in UNIX programs is handled in Java either by having a thread respond to a
synchronous request or by the use of exceptions.
Synchronization
Synchronization is the method of ensuring that multiple threads coordinate their activities so that
one thread doesn't accidentally change data that another thread is working on. This is done by
providing function calls that can limit the number of threads that can access some data
concurrently.
In the simplest case (a mutual exclusion lock--a mutex), only one thread at a time can execute a
given piece of code. This code presumably alters some global data or performs reads or writes to a
device. For example, thread T1 obtains a lock and starts to work on some global data. Thread T2
must now wait (typically, it goes to sleep) until thread T1 is done before T2 can execute the same
code. By using the same lock around all code that changes the data, we can ensure that the data
remains consistent.
Scheduling
Scheduling is the act of placing threads onto CPUs so that they can execute, and of taking them
off those CPUs so that others can run instead. In practice, scheduling is not generally an issue
because "it all works" just about the way you'd expect.
The Value of Using Threads
There is really only one reason for writing MT programs--to get better programs more quickly. If
you're an Independent Software Vendor (ISV), you sell more software. If you're developing
software for your own in-house use, you simply have better programs to use. The reason you can
write better programs is that MT gives your programs and your programmers a number of
significant advantages over nonthreaded programs and programming paradigms.
A point to keep in mind here is that you are not replacing simple, nonthreaded programs with
fancy, complex, threaded programs. You are using threads only when you need them to replace
complex or slow nonthreaded programs. Threads are just one more way to make your
programming tasks easier.
The main benefits of writing multithreaded programs are:
Performance gains from multiprocessing hardware (parallelism)
Increased application throughput
Increased application responsiveness
Replacing process-to-process communications
Efficient use of system resources
One binary that runs well on both uniprocessors and multiprocessors
Search WWH :
Custom Search
Previous Page
Multithreaded Programming with JAVA - Topic Index
Next Page
Multithreaded Programming with JAVA - Bookmarks
Home