OH2 Syntax

Please help with migrating to OH2.
What is syntax for ReentrantLock?

This syntax is not valid in OH2:

var Lock lock_oled = new ReentrantLock()
	if (!lock_oled.isLocked) {
		lock_oled.lock
		try{
		...
                } finally {
			lock_oled.unlock
		}
       }

Have you tried using “()” after lock and unlock? These are functions and this may be the source of the problem:

if (!lock_oled.isLocked) {
    lock_oled.lock()
    try{
        ...
    } finally {
        lock_oled.unlock()
    }
}

If not, what is the specific error you’re getting?

Variable definition still requires import (but OH2 manual says that no import needed), so i add import, and designer shows no errors.

import java.util.concurrent.locks.ReentrantLock

Thank you for answer.

Glad you have it sorted, can you point us towards that page? So we can fix that?

Its my mistake, tutorial says about only reference org.openhab.

1 Like