When running threads, there is no guarantee of any sort of ordering. You'll receive different orderings when you run this multiple times. Both of these were from running the app:
Duke: Who's there?
Coffee shop: Knock Knock!
Coffee shop: Duke
Duke: Duke who?
Coffee shop: Knock Knock!
Duke: Who's there?
Duke: Duke who?
Coffee shop: Duke
As to why: because the operating system decides arbitrarily what threads to run. There's really no predictable order that the operating system will run your threads. I tried to get this code working for some time, and was unable to get the threads to print in order. Due to the use of Exchanger, normal locking or synchronizing will not work. Threading is a difficult topic! Does the book have a solution that prints in order?