setTimeout throws 'Multi Threaded Access Requested' exception

  • Platform information:
    • Hardware: Intel x86-x64
    • OS: Windows 10 x64 Pro
    • Java Runtime Environment: Zulu JDK 11.54.23
    • openHAB version: openHAB 3.3.0.M1


I have the following script:


function test2(id) {;

function test(id) {;
  setTimeout(test2, 5.0*1000, id);

Log output is:

2022-03-01 15:41:08.280 [INFO ] [n.script.ui.SkriptRollladensteuerung] - 1
2022-03-01 15:41:08.343 [INFO ] [n.script.ui.SkriptRollladensteuerung] - 2
2022-03-01 15:41:08.343 [INFO ] [n.script.ui.SkriptRollladensteuerung] - 3
2022-03-01 15:41:13.328 [INFO ] [n.script.ui.SkriptRollladensteuerung] - 1
2022-03-01 15:41:13.359 [INFO ] [n.script.ui.SkriptRollladensteuerung] - 3
2022-03-01 15:41:13.359 [WARN ] [ore.internal.scheduler.SchedulerImpl] - Scheduled job failed and stopped
java.lang.IllegalStateException: Multi threaded access requested by thread Thread[OH-scheduler-213,5,main] but is not allowed for language(s) js.
	at ~[bundleFile:?]
	at ~[bundleFile:?]
	at ~[bundleFile:?]
	at ~[bundleFile:?]
	at ~[bundleFile:?]
	at ~[bundleFile:?]
	at ~[bundleFile:?]
	at ~[bundleFile:?]
	at ~[bundleFile:?]
	at com.sun.proxy.$Proxy228.apply(Unknown Source) ~[?:?]
	at org.openhab.core.model.script.actions.ScriptExecution.lambda$1( ~[bundleFile:?]
	at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$12( ~[?:?]
	at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$1( ~[?:?]
	at java.util.concurrent.Executors$ [?:?]
	at [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker( [?:?]
	at java.util.concurrent.ThreadPoolExecutor$ [?:?]
	at [?:?]
Caused by:$LazyStackTrace

Why is this happening?

How can I create multiple timers in one script instead?


Of course I already read that thread, but it doesn’t contain a solution and it seems they are talking about calling a script (with included timer) multiple times. My script runs only 1x at the same time, but should be able to create multiple timers. So I don’t understand why those timer callbacks are not running synchronously each one after another.

So I only allowed to use one timer per script?


Depending on the time and a lot of other states I want to control up to 8 (and in the future even more) roller shutters. Sometimes it happens, that one of those roller shutters not getting the signal to go up/down, so that I have to resend the signal.

My idea was to get the current roller shutter level, send the new value and after e.g. 5s I want to check if the new current value is different than the old current value, if not I resend the new value, otherwise everything is OK.

So if there is no solution to create multiple timers for each roller shutter, I have to create only one, and have to store all current values in a list and compare them with the new current values to determine which roller shutters needs to get the new value again.

Well, of course.

No, it doesn’t.

That is the current situation, yes.
To overcome the limitation, use another rule scripting language temporarily.