0

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.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
Homewrecker
  • 1,076
  • 1
  • 15
  • 38
  • 1
    The second answer [here](https://stackoverflow.com/questions/16758346/how-pause-and-then-resume-a-thread) might help – John Williams Mar 13 '23 at 09:34
  • 1
    Can you add some more context? Did you try to solve this with threads (e.g., handling these events in separate threads)? How does your Java code receive these events? – Sky Mar 13 '23 at 09:51
  • *Must* the event processing halt the main program? If not, there are trivial solutions. – Bohemian Mar 13 '23 at 10:35

0 Answers0