[SOLVED] Most rules stop working after a few days/week/ on Openhab 2.4

Well, the running out of Rules threads problem is highly timing driven. An upgrade or change in OH version is necessarily going to change the timing so situations where it used to work before but doesn’t know often are because either something is taking longer now or you were just lucky before.

As far as the fundamentals are concerned, the issue has existed since the beginning of OH. There are a limited number of Rules that can run at the same time. If you have long running Rules, you run a risk of running out of those threads and all your Rules end up stopping.

Also, not many users write their Rules once and never change them. It seems equally if not more likely that the user changed a Rule or added a Rule that changes the timing enough that it becomes a problem.

executeCommandLine and the sendHttp*Request Actions can be a problem too. And locks are a huge potential problem.

NGRE will become the default. And it supports Jython, JavaScript, and Groovy. It’s quite mature and with the helper libraries it is almost as easy to write Rules in these languages as the Rules DSL. I do not hesitate to recommend working in JSR223.

Lambdas will run in the same thread so they will not solve this issue. You can move your long running code to Timers, but there are only two Timer threads (by default) so you run the risk of just moving your problem instead of solving it.

The reason lambdas are frowned upon are:

  • they are not thread safe, if the same instance of a lambda is called from two separate Rules at the same time, they will stomp over each other
  • exceptions get hidden and you end up with a much less useful error message
  • most of the time they are unnecessary; there are other ways to achieve the same reduction in duplicated code
1 Like