|
Adam Chapman <adamchapman1985@hotmail.co.uk> wrote in message <042d5d82-1e7f-4b0e-b440-bdcb0cf2023f@m22g2000yqh.googlegroups.com>...
> Im running a java routine in a loop, but the code keeps crashing on
> the second iteration of the loop because the 1st hasn't finished I
> think.
>
> The problem is the java routine I'm calling in the loop doesn't return
> a value, so I can't make matlab wait to see something returned.
>
> Can anyone offer some advice?
>
> Thanks
> Adam
I can't help much with the rejected execution exception thingy (which looks like a question to ask on a Java forum). But here's a general advice for waiting in Matlab on Java functions that do not return any value:
There are of course the simple solutions of adding pause() calls, or synchronizing on some common object or property value.
In addition, if you look inside the built-in awtinvoke.m, you'll see two additional alternatives:
1. Use the built-in com.mathworks.jmi.AWTUtilities.invokeAndWait() function. If you look toward the bottom of awtinvoke.m you'll see that if no output arg is expected then Matlab uses the asynchronous invokeLater() method, but you can use the synchronous invokeAndWait() instead by a simple fix.
2. Use awtinvoke's deeply-hidden ability to specify a Matlab callback function that gets invoked when the Java function returns: simply use the awtinvoke(..., @funcHandle, funcArg1, funcArg2, ...) syntax.
Yair Altman
http://UndocumentedMatlab.com
|