I tried a few times with different code, it seems that the run() of producer somehow doesn't execute to the end. The print was never shown nor map updated. So in the run() of consumer, the map.isEmpty() always true. I can't figure out why. They have different threads, but the thread for Producer's run() only executes half way?