Exercises
-
Take the MyFrame program that demonstrates the thread bug and update it to reproduce the race condition more easily. Change the arithmetic that updates variable i into two statements, and put a
sleep()
or ayield()
statement between them. Observe the failure. -
Update the MyFrame program to remove the race condition by making the reading and writing of the variables mutually exclude each other. Test your code by running it on a version of the program that quickly reproduces the race condition failure.
-
Write a small Java program to capture the screen, display it in a scroll panel inside a frame, and allow the user to trim its size. Write the cropped region to a file on request. Allow the user to choose any output file format ...
Get Just Java™ 2 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.