# Is system.util.sendMessage receiver on gateway scope multithreaded?

**URL:** <https://forum.inductiveautomation.com/t/is-system-util-sendmessage-receiver-on-gateway-scope-multithreaded/51904>\
**Category:** Ignition\
**Created:** [October 13, 2021, 5:17pm UTC](https://forum.inductiveautomation.com/t/is-system-util-sendmessage-receiver-on-gateway-scope-multithreaded/51904 "2021-10-13T17:17:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [October 13, 2021, 5:17pm UTC](https://forum.inductiveautomation.com/t/is-system-util-sendmessage-receiver-on-gateway-scope-multithreaded/51904/1 "2021-10-13T17:17:55Z")

</div>

If many sources are throwing messages to the gateway scope using system.util.sendMessage, can multiple message handlers be running in parallel threads on the receive side? Would I have to explicitly add a mutex when I wanted to serialize the handling?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 13, 2021, 5:24pm UTC](https://forum.inductiveautomation.com/t/is-system-util-sendmessage-receiver-on-gateway-scope-multithreaded/51904/2 "2021-10-13T17:24:50Z")

</div>

It looks like they are executed on either a dedicated or shared executor but the pool size in either case is always 1, so it seems they are effectively serialized in the end.

edit: per handler, so multiple messages to the same handler are serialized, but multiple messages to multiple handlers are not.

---

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [October 13, 2021, 5:29pm UTC](https://forum.inductiveautomation.com/t/is-system-util-sendmessage-receiver-on-gateway-scope-multithreaded/51904/3 "2021-10-13T17:29:59Z")

</div>

If I have a particularly slow handler that I would like to multi-thread, what’s the sanest way to effectively spawn/fork a sub-function and allow the message handler to return to idle and get the next message?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 13, 2021, 5:32pm UTC](https://forum.inductiveautomation.com/t/is-system-util-sendmessage-receiver-on-gateway-scope-multithreaded/51904/4 "2021-10-13T17:32:36Z")

</div>

I would recommend setting up a private thread pool (see my [later.py](https://www.automation-pros.com/ignition/later.py) for an example). But you can use invokeAsynchronous() to give each its own thread.
