Writing multithreaded java applications is not a piece of cake. Extra care must be taken because bad synchronization can bring…