# (OH 1.x and OH 2.x Rules DSL only\] Why have my Rules stopped running? Why Thread::sleep is a bad idea

**URL:** <https://community.openhab.org/t/oh-1-x-and-oh-2-x-rules-dsl-only-why-have-my-rules-stopped-running-why-thread-sleep-is-a-bad-idea/47695>\
**Category:** Scripts & Rules\
**Tags:** rules\
**Created:** [July 11, 2018, 6:04pm UTC](https://community.openhab.org/t/oh-1-x-and-oh-2-x-rules-dsl-only-why-have-my-rules-stopped-running-why-thread-sleep-is-a-bad-idea/47695 "2018-07-11T18:04:50Z")\
**Posts on this page:** 1\
**Showing post:** 56

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [October 2, 2018, 3:24pm UTC](https://community.openhab.org/t/oh-1-x-and-oh-2-x-rules-dsl-only-why-have-my-rules-stopped-running-why-thread-sleep-is-a-bad-idea/47695/56 "2018-10-02T15:24:52Z")

</div>

> [@Nicholas\_Waterton](#):
>
> We need a way to tell how many rules are running, other than through the console, that way, I could log what is happening, and maybe catch the problem, before the rules grind to a halt.

See [New Add-on bundle for Prometheus health Metrics](https://community.openhab.org/t/new-add-on-bundle-for-prometheus-health-metrics/48094). They have included the thread pools as a metric they can report on.

But all of this can only tell you when you start to consume all your Rules threads, not which Rule is the source of the problem. But perhaps a time when the problem starts will b enough.

> [@Nicholas\_Waterton](#):
>
> so does this mean all my threads are in use?

Yes

> [@Nicholas\_Waterton](#):
>
> I have boiled my rules down to several lambdas that are called by rules that are 3 or 4 lines (mostly logging to try to find this problem).

Are you using ReentrantLocks? Locks can be troublesome and locks in lambdas can be particularly troublesome because you cannot guarantee that the finally will get executed and that your lock will be unlocked in every possible circumstance.

Lambdas have lots of other problems too (e.g. not thread safe and internal variables appear to be reused on each call so if you have two rules calling the same lambda at the same time they can stomp on each other) so I recommend against their use except in rare circumstances where there is no other viable way. Writing more generic Rules (i.e. all the Rules that need the lambda get merged into one so there is no need for the lambda anymore) or using an alternative approach such as the Separation of Behaviors DP results in fewer problems like these.

---

_[View the full topic](https://community.openhab.org/t/oh-1-x-and-oh-2-x-rules-dsl-only-why-have-my-rules-stopped-running-why-thread-sleep-is-a-bad-idea/47695)._
