Managing multiple asynchronous threads

To manage long-running jython threads through scripting restarts, you need to:

  1. Place the thread object in a dictionary that retains its content through script restarts. I used to recommend the dictionary from system.util.getGlobals(), but that is no longer suitable. I created a free Life Cycle Module that provides such dictionaries going forward.

  2. Write the asynchronous function’s loop so that it regularly checks Thread.interrupted(), particularly after any java I/O operations. Clean up and return when true.

  3. Write the asynchronous function’s startup section to grab the persistent dictionary, look up any thread already on its own key, and if present, .interrupt() and join() it. Then place the function’s own thread, Thread.currentThread(), into the persistent dictionary in that same key. Then proceed with the rest of your startup logic (including picking up any saved state from a prior thread’s cleanup).

2 Likes