Annotations 761
Basic syntax ....................... 762
Defining annotations ................. 762
Meta-annotations ...................... 763
Writing
annotation processors ........ 765
Annotation elements ................. 765
Default value constraints ........... 766
Generating external files............ 766
Annotations don’t
support inheritance ................... 769
Implementing the processor...... 769
Using apt to
process annotations ............ 772
Using the Visitor pattern
with apt .............................. 775
Annotation-based
unit testing .......................... 778
Using @Unit with generics ....... 785
No “suites” necessary .................786
Implementing @Unit ............... 787
Removing test code .................... 792
Summary ............................. 795
Concurrency 797
The many faces of
concurrency ....................... 798
Faster execution .........................798
Improving code design ............. 800
Basic threading .................. 801
Defining tasks ............................ 801
The Thread class ..................... 802
Using Executors ..................... 804
Producing return values
from tasks ................................. 806
Sleeping ..................................... 808
Priority ...................................... 809
Yielding ...................................... 810
Daemon threads ......................... 810
Coding variations ....................... 814
Terminology ............................... 819
Joining a thread ......................... 819
Creating responsive
user interfaces ............................ 821
Thread groups ........................... 822
Catching exceptions .................. 822
Sharing resources .............. 824
Improperly
accessing resources ................... 825
Resolving shared
resource contention ................... 827
Atomicity and volatility ............. 831
Atomic classes ........................... 836
Critical sections .......................... 837
Synchronizing on
other objects .............................. 841
Thread local storage ..................843
Terminating tasks .............. 844
The ornamental garden ............ 844
Terminating when blocked ........ 847
Interruption .............................. 848
Checking for an interrupt .......... 854
Cooperation
between tasks ..................... 856
wait() and notifyAll() ............ 857
notify() vs. notifyAll() ........... 861
Producers and consumers ........ 863
Producer-consumers
and queues ................................ 868
Using pipes for I/O
between tasks ............................. 872
Deadlock ............................. 874
New library
components ........................ 879
CountDownLatch .................. 879
CyclicBarrier .......................... 881
DelayQueue ........................... 883
PriorityBlockingQueue....... 885
The greenhouse controller
with ScheduledExecutor ...... 887
Semaphore ............................. 890
Exchanger .............................. 893
Simulation .......................... 896
Bank teller simulation .............. 896
The restaurant simulation ........ 900
Distributing work ..................... 904
Performance tuning ........... 909
Comparing
mutex technologies ................... 909
Lock-free containers .................. 916
Optimistic locking...................... 922
ReadWriteLocks .................... 923
Active objects ..................... 925
Summary ............................ 929
Further reading .......................... 931
Graphical
User Interfaces 933
Applets ............................... 935
Swing basics ....................... 935
A display framework .................. 937
Making a button ................. 938
Capturing an event ............. 939
Text areas ........................... 941
Controlling layout .............. 942
BorderLayout ......................... 942
FlowLayout ............................. 943
GridLayout .............................. 944
GridBagLayout....................... 944