I have two Threads, ThreadA (Main) with the methods j() and k(){...j()...} and a second Thread, ThreadB. ThreadA randomly calls method k(), which, among others, calls method j(). ThreadB randomly calls method j().
Now method k() and j() can not be executed at the same time as they share variables.
How can I make sure that ThreadB is only able to call method j() if ThreadA is not currently executing method k()? And also that ThreadB will execute j() after ThreadA finished executing k().
I read about the synchronized keyword but it seems that it can only cover one method. (e.g. ThreadX and ThreadY both access method m()).