. . .
Chapter 17. Examples
Threads and Windows
Displaying Things for a Moment (
Socket Server (Master/Slave Version)
Socket Server (Producer/Consumer Version)
Making a Native Call to pthread_setconcurrency()
Actual Implementation of POSIX Synchronization
A Robust, Interruptible Server
Disk Performance with Java
Other Programs on the Web
In which several complete programs are presented. The details and issues surrounding the way
they use threads are discussed, and references to other programs on the Net are made.
This chapter contains several example programs that use Java threads. The examples use threads
to demonstrate different concepts from previous chapters. All the example code (except for the
JNI example) has been compiled and run on Solaris, IRIX, Digital UNIX, and Windows NT.
Use this code in whatever manner you choose; many of the concepts demonstrated in the
examples can be reworked to be used in your applications. Of course, there are some bugs in the
code somewhere. All the source code used in this topic is available on the Web (see Code
Threads and Windows
This example (Code Example 17-1) uses threads to speed up the operation of a GUI program
which has long running operations. Without threads, this program would have to wait for each
long-running operation to complete before the next button could be pushed.
Example 17-1 ThreadedSwing Program
When the user pushes a button, disable it and sleep for 6 seconds.
If "Threaded," do the sleeping in a new thread, allowing the
other buttons to remain active. If "Non-Threaded," do the sleeping
in the SWING thread, effectively disabling the other buttons.
After sleeping, reenable the button by calling invokeLater().
(Swing is NOT thread-safe.)
CF: Same program in AWT: ThreadedAWT and in PThreads: ThreadWin.c
Search WWH :
Custom Search
Previous Page
Multithreaded Programming with JAVA - Topic Index
Next Page
Multithreaded Programming with JAVA - Bookmarks