My Java code is minding its own business, doing what I told it to do but at some moment in time, something can happen (an event). When this event occurs, I want my normal Java workflow to PAUSE, and execute code that can only be executed when the event occurs. When the "PAUSE code" is executed and the event has been dealt with, I want the normal Java workflow to resume. So my code should resume doing what it was doing.
Is this possible in Java, and if so, how can I achieve this?
I tried using a try/catch, but when you are inside the catch, you lose the context of the execution flow, so it's not possible to go back to the code in the try-clause.