Thread Subject:
Using Java Timer in Matlab

Subject: Using Java Timer in Matlab

From: Marco

Date: 26 Feb, 2010 14:38:04

Message: 1 of 3

I'd like to use a Java Timer (util.java.Timer) instead of matlab timer object. My only problem is that Java Timer Class need to define a TimerTask derived class with the proper run() method. How can i invoke Matlab code in the run method?

Thanks in advice for any useful information

Subject: Using Java Timer in Matlab

From: Yair Altman

Date: 27 Feb, 2010 18:19:04

Message: 2 of 3

"Marco " <francociccio@hotmail.com> wrote in message <hm8mcc$1rj$1@fred.mathworks.com>...
> I'd like to use a Java Timer (util.java.Timer) instead of matlab timer object. My only problem is that Java Timer Class need to define a TimerTask derived class with the proper run() method. How can i invoke Matlab code in the run method?
>
> Thanks in advice for any useful information

You'll need to use JMI to call Matlab from Java. Note however, that JMI needs to wait for the main Matlab computational thread, so the benefits of using a Java thread may be diminished.

Yair Altman
http://UndocumentedMatlab.com

Subject: Using Java Timer in Matlab

From: Yair Altman

Date: 28 Feb, 2010 17:59:06

Message: 3 of 3

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <hmbnmo$eue$1@fred.mathworks.com>...
> "Marco " <francociccio@hotmail.com> wrote in message <hm8mcc$1rj$1@fred.mathworks.com>...
> > I'd like to use a Java Timer (util.java.Timer) instead of matlab timer object. My only problem is that Java Timer Class need to define a TimerTask derived class with the proper run() method. How can i invoke Matlab code in the run method?
> >
> > Thanks in advice for any useful information
>
> You'll need to use JMI to call Matlab from Java. Note however, that JMI needs to wait for the main Matlab computational thread, so the benefits of using a Java thread may be diminished.
>
> Yair Altman
> http://UndocumentedMatlab.com


I just though of a neat hack that would bypass the need for JMI: in your Java run() code, simply raise an event (see http://www.mathworks.com/matlabcentral/newsreader/view_thread/272321 for sample code) on a Java object that is loaded in Matlab. In Matlab, listen on this event using a simple callback or a handle.listener. Then the corresponding Matlab callback code would be invoked when the Java run() is encountered.

Yair Altman
http://UndocumentedMatlab.com

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
undocumented Yair Altman 27 Feb, 2010 13:24:06
java Yair Altman 27 Feb, 2010 13:24:06
timertask Marco 26 Feb, 2010 09:39:10
timer Marco 26 Feb, 2010 09:39:10
java Marco 26 Feb, 2010 09:39:10
matlab Marco 26 Feb, 2010 09:39:10
rssFeed for this Thread

Contact us