tags:

views:

112

answers:

3

Hi everybody I write java class with the main method and I invoke method from matlab which takes long time and the program run other method which takes less time before the method of matlab. I want to run the method from matlab to be execute first then I want the other method to execute so can you help me please

Thanks

+2  A: 

Sounds like you need threads. You may find Sun's concurrency tutorial useful.

Basically, you can do something like this:

public static void main(String[] args) {
    Runnable r = new Runnable() {
        public void run() {
            doMethod();
            doOtherMethod();
        }
    }
    new Thread(r).start();
    doAnotherMethod();

See also the Javadocs for Thread and Runnable.

Michael Myers
A: 

Have a look at the java.util.concurrent package. This has functionality for executing tasks in parallell and coordinating tasks.

stili
A: 

I think you want to use the Matlab Thread's join() method to wait for the thread to die before continuing to the other method.

I am not sure whether that's what you mean by "the method from matlab to be execute first then I want the other method to execute".

I just don't know. The question is kind of interesting, but why didn't you provide the code you are using to call the matlab method, as you say "I invoke method from matlab". Perhaps if you showed how?

Peter Perháč