Question about scripts and how they are loaded

Hi all,

I have a question about scripts (in my case groovy) and how they are managed. I can see that they are based on Java’s JSR-223 capability but I do not fully understand how they are loaded inside openhab.

Specifically I have a doubt about how I should manage a ScheduledExecutorService thread pool. I make use of such objects often in my scripts to schedule things after a delay or at a specific time, but I’m afraid that I might be leaking by not managing correctly it’s disposal.

So the question is… what happens when I modify a script file and openhab reloads it in real time? What happens to any object that was held in memory by the previous script? Do I have a way to detect that my script is being unloaded or replaced and do some cleaning?

Here’s an even deeper question… To optimise some of my scripting I’ve gathered some common things in a “TRule” java class that extends the SimpleRule provided by openhab. I placed this class in a Java library and chucked it in my installation classpath.
When I write my groovy scripts, my rules extend TRule instead of SimpleRule and I could potentially add a convenience lazy method in TRule to generate the ScheduledExecutorService. If that was a static variable in the TRule class (which lives in the Java library and not the script file) would it be disposed when groovy scripts that extend that class are reloaded.

Thank you for any insight.