Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

java.net.URL

Thread view: 
Bob Smith - 19 Jun 2005 18:53 GMT
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
Signature

http://www.kolumbus.fi/bob.smith

Andrew Thompson - 19 Jun 2005 19:41 GMT
> Hiya all

Hey y'all.. how-y'alldoin'?

> have a question,

Have a shift* key?  Please apply it at the start of each sentence.
<http://www.physci.org/kbd.jsp?key=shift>

>..anyone a wiz on java.net.URL??

Yes.  (Not me, but certainly other people.)

> <code>
> try{
[quoted text clipped - 4 lines]
> }catch( ... ){
>         ..something went wrong....

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

> }
> </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>

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Bjorn Borud - 19 Jun 2005 21:17 GMT
[Bob Smith <bobsmith1@marketweighton.com>]

| have a question, anyone a wiz on java.net.URL??
| <code>
[quoted text clipped - 12 lines]
| 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
Bjorn Borud - 19 Jun 2005 21:46 GMT
[Bob Smith <bobsmith1@marketweighton.com>]

| have a question, anyone a wiz on java.net.URL??
| <code>
[quoted text clipped - 12 lines]
| 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
Bob Smith - 20 Jun 2005 10:08 GMT
> [Bob Smith <bobsmith1@marketweighton.com>]
> |
[quoted text clipped - 19 lines]
>
> -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
Signature

http://www.kolumbus.fi/bob.smith

Bjorn Borud - 20 Jun 2005 10:09 GMT
[Bob Smith <bobsmith1@marketweighton.com>]
| <code>
|     public void SetPage(){
[quoted text clipped - 17 lines]
| 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
Bob Smith - 20 Jun 2005 11:09 GMT
> [Bob Smith <bobsmith1@marketweighton.com>]
> | <code>
[quoted text clipped - 45 lines]
> 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
Signature

http://www.kolumbus.fi/bob.smith

Andrew Thompson - 20 Jun 2005 10:24 GMT
>> [Bob Smith <bobsmith1@marketweighton.com>]
..
>>| <code>
..
>>|         SectionsHash.put("Background", new java.net.URL("...URL...") );
..
>>| </code>
..
> <code>
>                     Editor.setPage( new java.net.URL( "...url..." ) );
...
> </code>
..
> ..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.

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Lucy - 20 Jun 2005 17:02 GMT
> Hiya all
> have a question, anyone a wiz on java.net.URL??

You don't need to be a wiz to take a wiz ;-)

> <code>
> try{
[quoted text clipped - 14 lines]
> --
> http://www.kolumbus.fi/bob.smith


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.