Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
making matlab wait until it's processed a java command

Subject: making matlab wait until it's processed a java command

From: Adam Chapman

Date: 10 Jul, 2011 18:09:04

Message: 1 of 5

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

Subject: making matlab wait until it's processed a java command

From: Adam Chapman

Date: 10 Jul, 2011 18:33:04

Message: 2 of 5

On Jul 10, 7:09 pm, Adam Chapman <adamchapman1...@hotmail.co.uk>
wrote:
> 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

It seems even if I pause matlab for the java routine to finish its
job, I still get an error on the second call of the java routine:

"exception ocurred while handing off the splitter job to the pool:
null
java.util.concurrent.RejectedExecutionException
at java.util.concurrent.ThreadPoolExecutor
$AbortPolicy.rejectedExecution(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.reject(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.execute(Unknown Source)
at
jboost.atree.InstrumentedAlternatingTree.buildSplitters(InstrumentedAlternatingTree.java:
264)
at
jboost.atree.InstrumentedAlternatingTree.getCandidates(InstrumentedAlternatingTree.java:
209)
at jboost.controller.Controller.learn(Controller.java:368)
at jboost.controller.Controller.executeMainLoop(Controller.java:225)
at jboost.controller.Controller.startLearning(Controller.java:200)
at jboost.controller.Controller.main(Controller.java:93)"

I guess I need to stop the java session running before calling it a
second time? If anybody knows how to do that I'd be very thankful

Subject: making matlab wait until it's processed a java command

From: Yair Altman

Date: 10 Jul, 2011 19:40:10

Message: 3 of 5

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

Subject: making matlab wait until it's processed a java command

From: Yair Altman

Date: 11 Jul, 2011 03:13:08

Message: 4 of 5

3. If you have R2008a or later, use the built-in javaMethodMT function to force the java method to run synchronously, on the main Matlab Thread.

Yair Altman
http://UndocumentedMatlab.com

Subject: making matlab wait until it's processed a java command

From: Adam Chapman

Date: 11 Jul, 2011 18:46:35

Message: 5 of 5

On Jul 11, 4:13 am, "Yair Altman" <altmany...@gmailDEL.comDEL> wrote:
> 3. If you have R2008a or later, use the built-in javaMethodMT function to force the java method to run synchronously, on the main Matlab Thread.
>
> Yair Altmanhttp://UndocumentedMatlab.com

Thanks Yair,

I used the [a b]=dos() command in the end, it was just a lot easier
than getting bogged down with java commands that I just don't
understand again!

All the Best
Adam

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us