THE Java™ Programming Language, Fourth Edition

(Jeff_L) #1

Much more information on these packages, and on security in general in the virtual machine, is in Inside
Java™ 2 Platform Security, Second Edition.


25.8. java.sql Relational Database Access


The package java.sql provides the Java Database Connectivity™ (JDBC) package for using relational
databases. These classes and methods can be implemented directly by your database vendor or through the
industry-standard Open Database Connectivity (ODBC) interface. JDBC is, in effect, a mapping of ODBC. The
JDBC package and other issues about relational databases are covered in JDBC™API Tutorial and Reference,
Third Edition.


25.9. Utility Subpackages


Some of the utility classes in java.util are not independent classes but groups of related classes that
together provide a particular functionality. These classes are themselves grouped into subpackages within
java.util.[1]


[1] For pragmatic reasons the collections classes had to be defined at the top level of
java.util, rather than in a subpackage, because of the existing legacy collections.

25.9.1. Concurrency Utilities java.util.concurrent


The package java.util.concurrent, together with its subpackages provides a range of utilities for
writing efficient multithreaded applications. These utilities expand the in-built synchronization facilities of the
Java programming language to allow building concurrent applications that would not otherwise be possible
with synchronized code, and to simplify common synchronization tasks that would otherwise be tedious and
error-prone to write using the language facilities. The utilities provided can be divided into five categories:



  • Concurrent collections These were described in Chapter 21.
    Synchronizers A group of utility classes that simplify common synchronization tasks (discussed
    below).



Executor framework A framework for asynchronous task execution, including a flexible,
high-performance thread pool implementation.


Locks and Conditions Classes that provide locking and waiting capabilities that go beyond those of
the built-in monitor capabilities.


Atomic variables A set of classes that allow safe expression of lock-free and wait-free algorithms
within an application.


There are four synchronizer classes:


Semaphore A counting semaphore. Useful for many situations in which access to a resource must
be controlled. To use the resource a thread must acquire a (conceptual) permit, or token, from the
semaphore. If none is available then the thread blocks until one is. When finished with the resource
the thread releases the permit back to the semaphore to allow other threads to proceed. A counting
semaphore can hold an arbitrary number of permits; a binary semaphore is a semaphore with only one
permit.


CountDownLatch A utility for blocking until a given number of events have occurred or until
certain conditions hold. The latch is created with a given number of events to expect. Each thread that
triggers an event or sets a condition calls the countDown method which decrements the initial count.

Free download pdf