If your OpenHAB freezes because of high CPU usage…

…as one of mine did, one thing you may try is to configure the CPU affinity of the OpenHAB processes.

This may be done by hand on a running process, using taskset(1):

# Restrict any java process(es) and their 
# subprocesses (-a option) to CPUs 0 and 1 only
taskset -p -a 0x03 $(ps -axo pid,comm |grep java |cut -f1 -d' ')

Or it may be applied to the systemd service configuration, if you start OpenHAB that way, via the CPUAffinity option:

[Unit]
Description=openHAB - empowering the smart home
Documentation=https://www.openhab.org/docs/
Documentation=https://community.openhab.org
Wants=network-online.target
After=network-online.target

[Service]
Environment=OPENHAB_HOME=/usr/share/openhab
Environment=OPENHAB_CONF=/etc/openhab
Environment=OPENHAB_RUNTIME=/usr/share/openhab/runtime
Environment=OPENHAB_USERDATA=/var/lib/openhab
Environment=OPENHAB_LOGDIR=/var/log/openhab
Environment=OPENHAB_STARTMODE=daemon
EnvironmentFile=-/etc/default/openhab

User=openhab
Group=openhab

WorkingDirectory=/usr/share/openhab
ExecStart=/usr/share/openhab/runtime/bin/karaf ${OPENHAB_STARTMODE}
ExecStop=/usr/share/openhab/runtime/bin/karaf stop

SuccessExitStatus=0 143
RestartSec=5
Restart=on-failure
TimeoutStopSec=120

LimitNOFILE=102642

CPUAffinity=0,1
[Install]
WantedBy=multi-user.target

The examples above cause OpenHAB and any subprocesses to run only on CPUs 0 and 1. On a Raspberry Pi 4 B, for instance, that leaves two CPUs free for the operating system and other processes to use, hopefully addressing one of the possible causes of OpenHAB freezes.

What version of openHAB do you run?

Currently 3.4.4 on all devices, but the proposed mitigation applies to any OpenHAB version.