A simple multi-threading Java game with monitor pattern -- part7

preview_player
Показать описание

In this section, we changed game engine.
Instead of using monitor pattern to achieve the thread safety, we delegate the thread safety to the thread safe state variable. We also makes the Point immutable, so that it can be published outside of the VehicleTracker class without worrying about thread safety.

This version of code have better performance because deepCopy and create new instance each time is avoided. Because an immutable version of the state variable is returned to the caller, the calling thread will see the latest update instead of seeing possible stale data from a snapshot made in an early time.
Рекомендации по теме
visit shbcf.ru