Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

classloader - Java WebStart slow, requesting libraries from invalid folder

Problem and question: Java webstarted app looking for its classes in base folder instead of ./lib.

As suggested in similar question at Java Web Start applications ask repeatedly for un-existing files I have turned off the jar signing, to rule out the security issue, and the problem persists.

Below find the clean example on what is going over the network for this simple java program:

public static void main(String[] args) {
    // TODO code application logic here
    System.out.println("Hello World! Initializing the class from the jar residing in lib/ folder. Expecting heavy network traffic...");

    //This class resides in lib/SampleJavaLibrary.jar
    //Initializing it just to excercise the class loader problem
    CDummyClass sDummy = new CDummyClass();

    System.out.println("Done");

}

On the network (by wireshark), one can observe repeated requests for jars in base folder, On some calls I counted up to 10 retries, replied by web server with 404. Ultimately, the loadClass is successful, but only after 10 or more requests for nonexisting jars. Multiply this with the number of classes being accessed in given program, and you end up with very slow initialization. In this simple case, there are "only" 2 retries for this simple class.

It all starts normal, the jars are loaded, all is good and nice:

6   0.020921    192.168.1.35    192.168.1.130   HTTP    GET /mnt/vbox/workspace/WebStartSample/distC/launch.jnlp HTTP/1.1
8   0.028092    192.168.1.130   192.168.1.35    HTTP    HTTP/1.1 200 OK  (application/x-java-jnlp-file)
10  0.514038    192.168.1.35    192.168.1.130   HTTP    GET /mnt/vbox/workspace/WebStartSample/distC/lib/SampleJavaLibrary.jar HTTP/1.1 
11  0.520688    192.168.1.130   192.168.1.35    HTTP    HTTP/1.1 200 OK  (application/java-archive)
12  0.618640    192.168.1.35    192.168.1.130   HTTP    GET /mnt/vbox/workspace/WebStartSample/distC/WebStartSample.jar HTTP/1.1 
14  0.652541    192.168.1.130   192.168.1.35    HTTP    HTTP/1.1 200 OK  (application/java-archive)

This is where the trouble begins, at library class call:

16  0.943801    192.168.1.35    192.168.1.130   HTTP    GET /mnt/vbox/workspace/WebStartSample/distC/SampleJavaLibrary.jar HTTP/1.1 
18  0.991748    192.168.1.130   192.168.1.35    HTTP    HTTP/1.1 404 Not Found  (text/html)
22  0.997281    192.168.1.35    192.168.1.130   HTTP    GET /mnt/vbox/workspace/WebStartSample/distC/SampleJavaLibrary.jar HTTP/1.1 
24  1.004799    192.168.1.130   192.168.1.35    HTTP    HTTP/1.1 404 Not Found  (text/html)

Ultimately, after above retrying, the class is being found and initialized (!), most likely from the already existing jar, which was loaded at application startup.

Why is jnlp class loader looking into base folder, and why for so many retries, is beyond me. I did tried to run under debugger, but could not find the sources for class loaders and could not figure it myself.

FWIW here is my jnlp file, and yes, I did tried all variations of update tag, lazy, eager, no changes

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jnlp codebase="http://mydebian.mydomain/mnt/vbox/workspace/WebStartSample/distC"    href="launch.jnlp" spec="1.0+">
    <information>
        <title>WebStartSample</title>
        <vendor>user</vendor>
        <homepage href=""/>
        <description>WebStartSample</description>
        <description kind="short">WebStartSample</description>

    </information>
<update check="always"/>

    <resources>
<j2se version="1.5+"/>
<jar href="WebStartSample.jar" main="true"/>


    <jar href="lib/SampleJavaLibrary.jar"/>
</resources>
    <application-desc main-class="webstartsample.Main">

    </application-desc>
</jnlp>

I suspect there is something wrong with the JNLPClassLoader(), that is the particular loader used within the webstart.

Regards,

Robert

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Recommendations:

  1. Validate the JNLP using JaNeLA. It seems valid to my eye, but JaNeLA is the better judge.
  2. Include the package element for each Jar. This element is mentioned in the Resources section of the JNLP File Syntax (also expanded in the table at the top of the page). Chase the link in the page to the (downloadable only) API Specification for further details of the package element. And as an aside, the API Spec. is the single best resource on JWS. I wish Oracle would make it web-browsable.
  3. Index the Jar files.
  4. Continue to ask such great (well thought out, well researched, well presented) questions. :)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...