invokeAsynchronous wait()

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.

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

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

import java.lang.Thread as JThread

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

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.

It looks like Jython has a “synchronize” module that has some functions you can use to wrap a callable in a Java synchronized block:

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

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?

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?

1 Like

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