This seems to be a rather basic feature, and it would be immensely interesting to the student to understand their code but unfortunately, Java makes it rather difficult to implement. This is because a current thread cannot finely inspect its own state. It cannot even inspect the state of another thread of the same JVM. Instead, it is mandatory to use the full fledged debugger's interface, that is called JDI.
This seems to be a rather basic feature, and it would be immensely interesting to the student to understand their code but unfortunately, Java makes it rather difficult to implement. This is because a current thread cannot finely inspect its own state. It cannot even inspect the state of another thread of the same JVM. Instead, it is mandatory to use the full fledged debugger's interface, that is called JDI.
A good start to implement this feature could be https://github.com/landrey/animjavaexec, a free project that prototypes what we need to add to the PLM.