The minimum number is 2!
Here is a solution which prints out 2.
Here is a solution which uses semaphores to protect access to the display.
Killing the balls: balls1.zip
Freezing the balls: balls2.zip
Freezing revisited: balls3.zip
Your own CyclicBarrier: balls4-monitor.zip is a solution using monitors, balls4-semaphores.zip a solution using semaphores.
A solution using synchronized
: cars.zip
This solution is fair - the monitor methods are careful to change the direction of the traffic flow from time to time. Notice that fairness makes the solution much more complicated.