24.1* | ( Revising Listing 24.1 ) Rewrite Listing 24.1 to display the output in a text area, as shown in Figure 24.31. Figure 24.31. The output from three threads is displayed in a text area. |
24.2 | ( Racing cars ) Rewrite Exercise 16.17 using a thread to control car racing. Compare the program with Exercise 16.17 by setting the delay time to 10 in both programs. Which one runs animation faster? |
24.3 | ( Raising flags ) Rewrite Exercise 16.23 using a thread to animate flag rising . Compare the program with Exercise 16.23 by setting the delay time to 10 in both programs. Which one runs animation faster? |
24.4 | ( Synchronizing threads ) Write a program that launches one thousand threads. Each thread adds 1 to a variable sum that initially is zero. You need to pass sum by reference to each thread. In order to pass it by reference, define an Integer wrapper object to hold sum . Run the program with and without synchronization to see its effect. |
24.5 | ( Running fans ) Rewrite Exercise 16.11 using a thread to control fan animation. |
24.6 | ( Bouncing balls ) Rewrite Exercise 16.19 using a thread to animate ball movements. |
24.7 | ( Controlling a group of clocks ) Rewrite Exercise 16.14 using a thread to control clock animation. |
24.8 | ( Account synchronization ) Rewrite Listing 24.9, ThreadCoorperation.java, using object's wait() and notifyAll() methods . |
24.9 | ( Demonstrating ConcurrentModificationException ) The iterator is fail-fast . Write a program to demonstrate it by creating two threads that concurrently access and modify a set. The first thread creates a hash set filled with numbers , and adds a new number to the set every second. The second thread obtains an iterator for the set and traverses the set back and forth through the iterator every second. You will receive a ConcurrentModificationException because the underlying set is being modified in the first thread while the set in the second thread is being traversed. |
24.10* | ( Using synchronized sets ) Using synchronization, correct the problem in the preceding exercise so that the second thread does not throw Concurrent-ModificationException . |
24.11* | ( Demonstrating deadlock ) Write a program that demonstrates deadlock. |
24.12* | ( Using JProgressBar ) Create a program that displays an instance of JProgressBar and sets its value property randomly every 500 milliseconds infinitely. |