# invokeAsynchronous wait()

**URL:** <https://forum.inductiveautomation.com/t/invokeasynchronous-wait/38906>\
**Category:** Ignition\
**Created:** [September 21, 2020, 8:40pm UTC](https://forum.inductiveautomation.com/t/invokeasynchronous-wait/38906 "2020-09-21T20:40:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [September 21, 2020, 8:40pm UTC](https://forum.inductiveautomation.com/t/invokeasynchronous-wait/38906/1 "2020-09-21T20:40:34Z")

</div>

How do I call wait() from inside a function that is called using invokeAsynchronous? I have my class inheriting from java.lang.Thread. It looks like I need my code to be inside a synchronized block, but ignition does not recognize the word synchronized.

---

<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:** [September 21, 2020, 9:24pm UTC](https://forum.inductiveautomation.com/t/invokeasynchronous-wait/38906/2 "2020-09-21T21:24:06Z")

</div>

Can you take a few steps back and explain what you’re trying to accomplish?

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [September 21, 2020, 9:41pm UTC](https://forum.inductiveautomation.com/t/invokeasynchronous-wait/38906/3 "2020-09-21T21:41:06Z")

</div>

Sure. Here is example of where I want to put the wait.

```auto
import java.lang.Thread as JThread

class Subscriber(JThread):
    def getMessage(self):
        while 1==1:
            message = self.readMessage()
            if(message != None):
                self.doSomethingWithMessage(message)
            else:
                self.wait()

```

I will have other code that when it places a new message it will notify this thread, so that if it is waiting it will continue the while loop.

I also have other code that will call the getMessage by using system.util.invokeAsynchronous() then the thread that is returned is stored using system.util.getGlobals(). That is how I notify the thread or interrupt it.

There seems to be a lot more out there about using python/jython threading, but I would like to use java Thread since that is what system.util.invokeAsynchronous is using.

---

<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:** [September 21, 2020, 9:57pm UTC](https://forum.inductiveautomation.com/t/invokeasynchronous-wait/38906/4 "2020-09-21T21:57:15Z")

</div>

It looks like Jython has a “synchronize” module that has some functions you can use to wrap a callable in a Java synchronized block: [https://github.com/jython/jython/blob/master/src/org/python/modules/synchronize.java](https://github.com/jython/jython/blob/master/src/org/python/modules/synchronize.java)

Having trouble finding an example of its usage… might be a sign you’re messing around where you shouldn’t be.

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [September 21, 2020, 10:04pm UTC](https://forum.inductiveautomation.com/t/invokeasynchronous-wait/38906/5 "2020-09-21T22:04:54Z")

</div>

I was just thinking it would be easier to use java.lang.Thread since that is what is returned by system.util.invokeAsynchronous. Would you then recommend I use the python threading module instead?

---

<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:** [September 21, 2020, 10:06pm UTC](https://forum.inductiveautomation.com/t/invokeasynchronous-wait/38906/6 "2020-09-21T22:06:05Z")

</div>

the wait() and notify() functions I assume you’re talking about don’t have anything to do with Threads, they exist on every java.lang.Object.

I’m still not sure what you’re trying to build, but maybe using one of Java’s blocking queues would help you get it done? [https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/BlockingQueue.html](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/BlockingQueue.html)

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [September 21, 2020, 10:09pm UTC](https://forum.inductiveautomation.com/t/invokeasynchronous-wait/38906/7 "2020-09-21T22:09:27Z")

</div>

This may be exactly what I am looking for. I will look it over. Thanks.
