cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Use API in a Multithreaded Java environment

alros
Super Contributor

To prevent application hang, we have written Plugins for MEGA (MetaCommand) wich do their work in a Multithreaded way.

The following is a POC of what we are doing:

 

public void CmdInvoke(MegaObject o, Integer nCmd) {
    final MegaRoot mRoot = o.getRoot();
    Runnable worker = new Runnable() {
        // Wait a bit so CmdInvoke will be done
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {}
        // Try to reuse mRoot
        MegaCollection test = mRoot.getSelection("SELECT [Application] WHERE [Name] LIKE 'A#'");
        mRoot.print("Test okay. Size: " + test.size());
    };
    SwingUtilities.invokeLater(worker); // Do Asynchronous work
}

In MEGA 2009 CP5 this design principle worked, but in HOPEX V1R2 it does not. When the asynchronous thread tries to re-use the MegaRoot after CmdInvoke is done, the getSelection() fails with the Error message saying "Internal error while compiling the query".

 

If we instead try to re-generate a new root object from scratch using

public void CmdInvoke(MegaObject o, Integer nCmd) {
    MegaCurrentSession sess = new MegaCurrentSession();
    final MegaRoot mRoot = sess.getRoot("");
}

HOPEX throws the Error "Native object is not connected" on trying to get the root (i.e. we can't open a MegaCurrentSession from within the MEGA JVM).

 

How can we get a working MegaRoot from within the HOPEX JVM for concurrent use?

1 Reply

emilianonava
New Contributor

Hello, I have the same scenario. I also have an issue with the query. Is it possible to use concurrent threads? I'm working on Hopex v4