java.net.URL

A

Andrew Thompson


Hey y'all.. how-y'alldoin'?
have a question,

Have a shift* key? Please apply it at the start of each sentence.
..anyone a wiz on java.net.URL??

Yes. (Not me, but certainly other people.)
<code>
try{
SectionsHash = new HashMap();
SectionsHash.put("Background", new java.net.URL("...URL...") );
...and many more rows...

}catch( ... ){
..something went wrong....

Exactly what do you do here? (Specifically)
<http://www.physci.org/codes/javafaq.jsp#stacktrace>
}
</code>

creating URLs that way and putting them into a hash with key works very well
on windows, while on linux it hangs the program for a minute sort of.

...Does that mean the program 'sort of' hangs, or whatever
happens takes 'sort of' a minute?
Anyone experienced the same??
Probably.

..What could be the reason??

Most likely your code*, then (ever so slightly possible) a
JVM implementation bug. But I'd put my money on the former.

* Please supply an SSCCE that displays this behaviour
<http://www.physci.org/codes/sscce.jsp>
 
B

Bob Smith

Hiya all
have a question, anyone a wiz on java.net.URL??
<code>
try{
SectionsHash = new HashMap();
SectionsHash.put("Background", new java.net.URL("...URL...") );
...and many more rows...

}catch( ... ){
..something went wrong....
}
</code>

creating URLs that way and putting them into a hash with key works very well
on windows, while on linux it hangs the program for a minute sort of.
Anyone experienced the same??What could be the reason??
( any help much appreciated )
Greger
 
B

Bjorn Borud

[Bob Smith <[email protected]>]
|
| have a question, anyone a wiz on java.net.URL??
| <code>
| try{
| SectionsHash = new HashMap();
| SectionsHash.put("Background", new java.net.URL("...URL...") );
| ...and many more rows...
|
| }catch( ... ){
| ..something went wrong....
| }
| </code>
|
| creating URLs that way and putting them into a hash with key works
| very well on windows, while on linux it hangs the program for a
| minute sort of. Anyone experienced the same??What could be the
| reason?? ( any help much appreciated )

if for some reason the hashCode() of the URL gets called, that would
trigger hostname resolution. it looks like this is what happens when
you construct a HashMap.Entry (ie. when you insert a key/value pair
into HashMap):

public int hashCode() {
return (key==NULL_KEY ? 0 : key.hashCode()) ^
(value==null ? 0 : value.hashCode());
}

-Bjørn
 
B

Bjorn Borud

[Bob Smith <[email protected]>]
|
| have a question, anyone a wiz on java.net.URL??
| <code>
| try{
| SectionsHash = new HashMap();
| SectionsHash.put("Background", new java.net.URL("...URL...") );
| ...and many more rows...
|
| }catch( ... ){
| ..something went wrong....
| }
| </code>
|
| creating URLs that way and putting them into a hash with key works
| very well on windows, while on linux it hangs the program for a
| minute sort of. Anyone experienced the same??What could be the
| reason?? ( any help much appreciated )

if for some reason the hashCode() of the URL gets called, that would
trigger hostname resolution.

-Bjørn
 
B

Bjorn Borud

[Bob Smith <[email protected]>]
| <code>
| public void SetPage(){
| String helpURL = G.GetSection( cmb.getSelectedItem().toString() );
| if (helpURL != null) {
| try {
| Editor.setPage( new java.net.URL( "...url..." ) );
| } catch (IOException ex) {
| System.err.println("Attempted to read a bad URL: " +
| helpURL);
| }
| } else {
| System.err.println("Couldn't find URL:" + helpURL );
| }
| }
| </code>
| Hi again
| tracked down the problem to this code snippet.
| the linux box hangs for a minute in this function/method.
|
| The reason is the URL constructor, what is time consuming there in htat
| constructor?

I have no idea. without knowing what Editor.setPage() does, I have no
idea what your problem might be. I don't *think* the URL constructor
should be the problem here. what if you declare a local URL variable,
construct he URL object and assign it to this variable and then make
the setPage() call using this as the argument, so that you can measure
the time this takes to see if it is really the *constructor* that
takes time. something like this:

import java.net.URL;
....
....
long t = System.currentTimeMillis();
System.err.println("before");
URL url = new URL( "...url..." );
System.err.println("after, took " + (System.currentTimeMillis() - t));
Editor.setPage(url);

....so you'll see if the URL constructor is the culprit.

as I suggested before, if the hashCode() method of URL gets called,
this will trigger address resolution of the host part of the URL,
which might, on a really badly configured¹ Linux box, take a while.


what does Editor.setPage() do? will this add URL to a Set or use it
as a key in a Map? (or even a value in a map which you later extract
the Map.Entry set for?).


¹) check /etc/resolv.conf if you have multiple nameservers entries in
the config and if the probing sequence contains DNS servers that
are unresponsive/dead.

-Bjørn
 
A

Andrew Thompson

Bjorn said:
[Bob Smith <[email protected]>] ...
| <code> ...
| SectionsHash.put("Background", new java.net.URL("...URL...") ); ...
| </code>
...
<code>
Editor.setPage( new java.net.URL( "...url..." ) ); ....
...
..tracked down the problem to this code snippet.

Stuff these 'code snippets', I say!

It would be a lot simpler for others to ascertain exactly
what is happening when you provide a single exactly reproducible
problem (as was expanded in the SSCCE document to which
I linked in my first reply).

Note that ..
a) The code has changed from first to second post.
adding an URL to a map is (probably) going to cause
a very different set of code instructions to be performed
than if you set an editor to the URL.
b) In only 1 in 15 cases[1] does the code snippet supplied actually
reveal the line/lines in code that are the problem.
c) These code snippets still do not reveal the actual contents
of the URL, which you have thus far listed as (the very unhelpful)
"...url..."

I could go on asking 20-30 questions that might help narrow
down the possibilites to what is actually happening, but
since it is your problem and I have already described to
you the best way to *answer* those questions (as well as the
100-500 that might be asked based on unexpected replies to the
20-30), I won't.

I feel this problem would be best advanced to a solution by
*you* supplying the exact code that are using.

[1] 86.7% of statistics are made up on the spot.
 
B

Bob Smith

Bjorn said:
[Bob Smith <[email protected]>]
|
| have a question, anyone a wiz on java.net.URL??
| <code>
| try{
| SectionsHash = new HashMap();
| SectionsHash.put("Background", new java.net.URL("...URL...") );
| ...and many more rows...
|
| }catch( ... ){
| ..something went wrong....
| }
| </code>
|
| creating URLs that way and putting them into a hash with key works
| very well on windows, while on linux it hangs the program for a
| minute sort of. Anyone experienced the same??What could be the
| reason?? ( any help much appreciated )

if for some reason the hashCode() of the URL gets called, that would
trigger hostname resolution.

-Bjørn
<code>
public void SetPage(){
String helpURL = G.GetSection( cmb.getSelectedItem().toString() );
if (helpURL != null) {
try {
Editor.setPage( new java.net.URL( "...url..." ) );
} catch (IOException ex) {
System.err.println("Attempted to read a bad URL: " +
helpURL);
}
} else {
System.err.println("Couldn't find URL:" + helpURL );
}
}
</code>
Hi again
tracked down the problem to this code snippet.
the linux box hangs for a minute in this function/method.

The reason is the URL constructor, what is time consuming there in htat
constructor?

help much appreciated.
G
 
B

Bob Smith

Bjorn said:
[Bob Smith <[email protected]>]
| <code>
| public void SetPage(){
| String helpURL = G.GetSection( cmb.getSelectedItem().toString()
| ); if (helpURL != null) {
| try {
| Editor.setPage( new java.net.URL( "...url..." ) );
| } catch (IOException ex) {
| System.err.println("Attempted to read a bad URL: " +
| helpURL);
| }
| } else {
| System.err.println("Couldn't find URL:" + helpURL );
| }
| }
| </code>
| Hi again
| tracked down the problem to this code snippet.
| the linux box hangs for a minute in this function/method.
|
| The reason is the URL constructor, what is time consuming there in htat
| constructor?

I have no idea. without knowing what Editor.setPage() does, I have no
idea what your problem might be. I don't *think* the URL constructor
should be the problem here. what if you declare a local URL variable,
construct he URL object and assign it to this variable and then make
the setPage() call using this as the argument, so that you can measure
the time this takes to see if it is really the *constructor* that
takes time. something like this:

import java.net.URL;
....
....
long t = System.currentTimeMillis();
System.err.println("before");
URL url = new URL( "...url..." );
System.err.println("after, took " + (System.currentTimeMillis() - t));
Editor.setPage(url);

...so you'll see if the URL constructor is the culprit.

as I suggested before, if the hashCode() method of URL gets called,
this will trigger address resolution of the host part of the URL,
which might, on a really badly configured¹ Linux box, take a while.


what does Editor.setPage() do? will this add URL to a Set or use it
as a key in a Map? (or even a value in a map which you later extract
the Map.Entry set for?).

Editor is a JEditorPane.
¹) check /etc/resolv.conf if you have multiple nameservers entries in
the config and if the probing sequence contains DNS servers that
are unresponsive/dead.

-Bjørn
uhhmm,.....wellll....
hehehe, I found out, I turned off the firewall and it worked like it should.
( firewall config issue )

sorry for the confusion and thanks for the help.

Greger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top