June 2005
Beginner to intermediate
312 pages
6h 24m
English
The puzzles in this chapter feature more advanced library topics, such as threading, reflection, and I/O.
This program consists entirely of synchronized static methods. What does it print? Is it guaranteed to print the same thing every time you run it?
public class PingPong { public static synchronized void main(String[ ] a) { Thread t = new Thread( ) { public void run( ) { pong( ); } }; t.run( ); System.out.print("Ping"); } static synchronized void pong( ) { System.out.print("Pong"); }}
In a multithreaded program, it is generally a good bet that the behavior can vary from run to run, but this program always ...