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:
Where is urlConnection.setReadTimeout?

Subject: Where is urlConnection.setReadTimeout?

From: Michele

Date: 14 Dec, 2009 19:07:02

Message: 1 of 7

In another thread, I asked about a way to keep Matlab from hanging if you try to access a web server that doesn't respond (see
http://www.mathworks.com/matlabcentral/newsreader/view_thread/164917#628434).

The concensus seemed to be that by adding a line like:

 urlConnection.setReadTimeout(5000) ;

to urlread, that would cause the needed timeout. In fact, someone posted that
"I added this on line 96 or urlread.m (R2006b) and it works."

However, it doesn't work for me (R13 v 6.5 in XP). If I say:

methodsview java.net.URLConnection

I get back a whole list of methods including various sets and gets, but "setReadTimeout" is not among them. My copy of java.net is apparently lacking this method.

Unfortunately, I don't understand where java.net comes from, and don't know how to figure it out. Is it the case that I'm simply pointing to an old version of this that lacks this method and needs to be updated from somewhere? At java.com perhaps? Or is java.net something written by Mathworks for Matlab? Do I need some new jar file?

I could really use some help if some kind soul who understands this could tell me what's going on with this. I'm really stuck here. Thanks.

Subject: Where is urlConnection.setReadTimeout?

From: Steven Lord

Date: 15 Dec, 2009 03:49:09

Message: 2 of 7


"Michele" <denber.nospam@mindspringNOSPAM.com> wrote in message
news:hg62cm$d73$1@fred.mathworks.com...
> In another thread, I asked about a way to keep Matlab from hanging if you
> try to access a web server that doesn't respond (see
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/164917#628434).
>
> The concensus seemed to be that by adding a line like:
>
> urlConnection.setReadTimeout(5000) ;
>
> to urlread, that would cause the needed timeout. In fact, someone posted
> that
> "I added this on line 96 or urlread.m (R2006b) and it works."
>
> However, it doesn't work for me (R13 v 6.5 in XP). If I say:
>
> methodsview java.net.URLConnection
>
> I get back a whole list of methods including various sets and gets, but
> "setReadTimeout" is not among them. My copy of java.net is apparently
> lacking this method.

Apparently this method was added to the URLConnection class in a later
version of Java than the one used by MATLAB 6.5 (R13).

> Unfortunately, I don't understand where java.net comes from, and don't
> know how to figure it out. Is it the case that I'm simply pointing to an
> old version of this that lacks this method and needs to be updated from
> somewhere? At java.com perhaps? Or is java.net something written by
> Mathworks for Matlab? Do I need some new jar file?

You need to use a newer version of Java -- since we only officially support
each version of MATLAB with the version of Java that ships with that
version, while you _could_ change the Java versoin for your installation I
would recommend instead upgrading your installation to a later version.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: Where is urlConnection.setReadTimeout?

From: Yair Altman

Date: 15 Dec, 2009 08:44:03

Message: 3 of 7

"Steven Lord" <slord@mathworks.com> wrote in message <hg70vk$dop$1@fred.mathworks.com>...
>
> "Michele" <denber.nospam@mindspringNOSPAM.com> wrote in message
> news:hg62cm$d73$1@fred.mathworks.com...
> > In another thread, I asked about a way to keep Matlab from hanging if you
> > try to access a web server that doesn't respond (see
> > http://www.mathworks.com/matlabcentral/newsreader/view_thread/164917#628434).
> >
> > The concensus seemed to be that by adding a line like:
> >
> > urlConnection.setReadTimeout(5000) ;
> >
> > to urlread, that would cause the needed timeout. In fact, someone posted
> > that
> > "I added this on line 96 or urlread.m (R2006b) and it works."
> >
> > However, it doesn't work for me (R13 v 6.5 in XP). If I say:
> >
> > methodsview java.net.URLConnection
> >
> > I get back a whole list of methods including various sets and gets, but
> > "setReadTimeout" is not among them. My copy of java.net is apparently
> > lacking this method.
>
> Apparently this method was added to the URLConnection class in a later
> version of Java than the one used by MATLAB 6.5 (R13).
>
> > Unfortunately, I don't understand where java.net comes from, and don't
> > know how to figure it out. Is it the case that I'm simply pointing to an
> > old version of this that lacks this method and needs to be updated from
> > somewhere? At java.com perhaps? Or is java.net something written by
> > Mathworks for Matlab? Do I need some new jar file?
>
> You need to use a newer version of Java -- since we only officially support
> each version of MATLAB with the version of Java that ships with that
> version, while you _could_ change the Java versoin for your installation I
> would recommend instead upgrading your installation to a later version.
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


To expand on Steve's answer, setReadTimeout() only became available in Java 1.5 (which was bundled with Matlab R14SP2=7.0.4 and higher on Windows), as seen here: http://java.sun.com/javase/6/docs/api/java/net/URLConnection.html#setReadTimeout%28int%29

Your Matlab version, R13 (=6.5) only contains Java 1.3.1. You can try to use the newer Java version as explained here: http://www.mathworks.com/support/solutions/en/data/1-1812J/

However, note that using a non-default Java version might cause unexpected problems in your Matlab.

Yair Altman
http://UndocumentedMatlab.com

Subject: Where is urlConnection.setReadTimeout?

From: Michele

Date: 15 Dec, 2009 17:09:02

Message: 4 of 7

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <hg7i8j$7lm$1@fred.mathworks.com>...

> Your Matlab version, R13 (=6.5) only contains Java 1.3.1. You can try to use the newer Java version as explained here: http://www.mathworks.com/support/solutions/en/data/1-1812J/

Thanks very much for the reply, and to Steve for his reply. I would dearly love to upgrade my copy of Matlab to the latest version but I simply cannot afford that right now. I went to java.com and downloaded and installed the latest JRE (v. 6, update 17) as well as the latest SDK (1.6.0) from java.sun.com.

I exited and restarted Matlab, but I still don't have setReadTimeout in the urlConnection class. Do I need to do something else? Some change to classpath.txt maybe? The link above contains some nice documentation on setReadTimeout, but nothing on how to get Matlab to use it. I've been up and down the help files but can't find anything that explains this.

Subject: Where is urlConnection.setReadTimeout?

From: Steven Lord

Date: 15 Dec, 2009 18:07:57

Message: 5 of 7


"Michele" <denber.nospam@mindspringNOSPAM.com> wrote in message
news:hg8fre$rtu$1@fred.mathworks.com...
> "Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message
> <hg7i8j$7lm$1@fred.mathworks.com>...
>
>> Your Matlab version, R13 (=6.5) only contains Java 1.3.1. You can try to
>> use the newer Java version as explained here:
>> http://www.mathworks.com/support/solutions/en/data/1-1812J/
>
> Thanks very much for the reply, and to Steve for his reply. I would
> dearly love to upgrade my copy of Matlab to the latest version but I
> simply cannot afford that right now. I went to java.com and downloaded
> and installed the latest JRE (v. 6, update 17) as well as the latest SDK
> (1.6.0) from java.sun.com.
>
> I exited and restarted Matlab, but I still don't have setReadTimeout in
> the urlConnection class. Do I need to do something else? Some change to
> classpath.txt maybe? The link above contains some nice documentation on
> setReadTimeout, but nothing on how to get Matlab to use it. I've been up
> and down the help files but can't find anything that explains this.

Yair gave you the solution (actually a link to the solution) in his reply;
in fact, you quoted it above. Read that document and follow the
instructions it gives for setting the environment variable.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: Where is urlConnection.setReadTimeout?

From: Michele

Date: 15 Dec, 2009 21:52:02

Message: 6 of 7

"Steven Lord" <slord@mathworks.com> wrote in message <hg8j9s$d14$1@fred.mathworks.com>...
> Yair gave you the solution (actually a link to the solution) in his reply;
> in fact, you quoted it above. Read that document and follow the
> instructions it gives for setting the environment variable.

Indeed. I have no idea why I got a page with the method documentation the first time - maybe I clicked on the wrong tab or something. Anyway, you are of course correct. The directions were in fact there, they were clear, I followed them, and I'm happy to report that everything worked fine.

I can now successfully run urlread in R13 without hanging the entire system if the site you're trying to read is down. This is great. Many many thanks for the assistance. I really appreciate your taking the time to reply and point out the error of my ways :-)

Subject: Where is urlConnection.setReadTimeout?

From: Kevin

Date: 21 Mar, 2010 07:17:40

Message: 7 of 7

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <hg7i8j$7lm$1@fred.mathworks.com>...
> "Steven Lord" <slord@mathworks.com> wrote in message <hg70vk$dop$1@fred.mathworks.com>...
> >
> > "Michele" <denber.nospam@mindspringNOSPAM.com> wrote in message
> > news:hg62cm$d73$1@fred.mathworks.com...
> > > In another thread, I asked about a way to keep Matlab from hanging if you
> > > try to access a web server that doesn't respond (see
> > > http://www.mathworks.com/matlabcentral/newsreader/view_thread/164917#628434).
> > >
> > > The concensus seemed to be that by adding a line like:
> > >
> > > urlConnection.setReadTimeout(5000) ;
> > >
> > > to urlread, that would cause the needed timeout. In fact, someone posted
> > > that
> > > "I added this on line 96 or urlread.m (R2006b) and it works."
> > >
> > > However, it doesn't work for me (R13 v 6.5 in XP). If I say:
> > >
> > > methodsview java.net.URLConnection
> > >
> > > I get back a whole list of methods including various sets and gets, but
> > > "setReadTimeout" is not among them. My copy of java.net is apparently
> > > lacking this method.
> >
> > Apparently this method was added to the URLConnection class in a later
> > version of Java than the one used by MATLAB 6.5 (R13).
> >
> > > Unfortunately, I don't understand where java.net comes from, and don't
> > > know how to figure it out. Is it the case that I'm simply pointing to an
> > > old version of this that lacks this method and needs to be updated from
> > > somewhere? At java.com perhaps? Or is java.net something written by
> > > Mathworks for Matlab? Do I need some new jar file?
> >
> > You need to use a newer version of Java -- since we only officially support
> > each version of MATLAB with the version of Java that ships with that
> > version, while you _could_ change the Java versoin for your installation I
> > would recommend instead upgrading your installation to a later version.
> >
> > --
> > Steve Lord
> > slord@mathworks.com
> > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
http://www.wikio.com/article/bad-credit-payday-loans-176415445
>
> To expand on Steve's answer, setReadTimeout() only became available in Java 1.5 (which was bundled with Matlab R14SP2=7.0.4 and higher on Windows), as seen here: http://java.sun.com/javase/6/docs/api/java/net/URLConnection.html#setReadTimeout%28int%29
>
> Your Matlab version, R13 (=6.5) only contains Java 1.3.1. You can try to use the newer Java version as explained here: http://www.mathworks.com/support/solutions/en/data/1-1812J/
>
> However, note that using a non-default Java version might cause unexpected problems in your Matlab.
>
> Yair Altman
> http://UndocumentedMatlab.com

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