Not sure if that's the problem , but you may want to declare isRunning as volatile - indicating its value can be altered in different threads.
From what I remember - you shouldn't rely on thread priorities for doing anything meaningful. Their implementation is (or used to be) very uneven and sometimes changed between JVM versions, so it is better not to rely on them. Maybe Henry will chime in on this, he'd know for sure.
Alexandru Gifei wrote:Declaring the flags as volatile did the job. Thanks!
True. I guess when the count is not volatile, the 2 threads tries to do code optimization by reading/writing the variable to cache/master location. Hence the 2 thread enter race condition and will not terminate.