Lazy downloads in JWS

Page Contents

Introduction

Java WebStart supposedly offers a lazy download facility, but developers report that it is difficult to get JWS to honor the 'lazy' attribute.

The JNLP Specification notes in the first paragraph of section 4.4 "Parts and Lazy Downloads".

".. a JNLP Client is always allowed to eagerly download all resources if it chooses."

One hopes this vague warning only applies to two situations

  • The client has ticked an 'install for off-line use' box in the JWS manager (I cannot see any such box, but perhaps Sun is considering adding one).
  • silent and CD installs, where it is intended to install a number of large resources off disk, then have the webstart manager simply check the net for updates.

Note that (old) examples 1-5 can be seen at javasaver.com.

Example 6

Example of 'lazy' download (of media) that provides a progress dialog for the end user.

Result 6

This example uses reflection to load media referenced in the JNLP file. The web-start DownloadService is used to load the media files, and provides a progess dialog as the resource is being fetched.

The entire process is called from a new thread, to ensure that it does not block the Event Dispatch Thread.

Still broken?!

Java Web Start 1.6.0
Using JRE version 1.6.0 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\Administrator
----------------------------------------------------
c:   clear console window
 ...
v:   dump thread stack
0-5: set trace level to <n>
----------------------------------------------------
DownloadServiceListener com.sun.jnlp.DownloadServiceImpl$DefaultProgressImpl@fec107
Part animal downloading!
jar:http://www.physci.org/jws/cache/media/animalmedia.jar!/image/DCP_7940.jpg
user cancelled action? ..proceed and try
DownloadServiceListener com.sun.jnlp.DownloadServiceImpl$DefaultProgressImpl@fec107
Part plant downloading!
java.lang.RuntimeException: canceled by user
	at com.sun.jnlp.DownloadServiceImpl$DefaultProgressImpl.progress(Unknown Source)
	at com.sun.jnlp.DownloadServiceImpl$ProgressHelper.(Unknown Source)
	at com.sun.jnlp.DownloadServiceImpl$6.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.jnlp.DownloadServiceImpl.loadPart(Unknown Source)
	at com.sun.jnlp.DownloadServiceImpl.loadPart(Unknown Source)
	at test.JWSCacheTest.run(JWSCacheTest.java:84)
	at java.lang.Thread.run(Unknown Source)
jar:http://www.physci.org/jws/cache/media/plantmedia.jar!/image/100_1829-800x600.jpg
Java Web Start 1.6.0
Using JRE version 1.5.0_08 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\Administrator
----------------------------------------------------
c:   clear console window
  ...
v:   dump thread stack
0-5: set trace level to <n>
----------------------------------------------------
DownloadServiceListener com.sun.jnlp.DownloadServiceImpl$DefaultProgressImpl@d9896e
Part animal downloading!
jar:http://www.physci.org/jws/cache/media/animalmedia.jar!/image/DCP_7940.jpg
Part plant cached!
jar:http://www.physci.org/jws/cache/media/plantmedia.jar!/image/100_1829-800x600.jpg
user cancelled action? ..proceed and try
DownloadServiceListener com.sun.jnlp.DownloadServiceImpl$DefaultProgressImpl@d9896e
Part art downloading!
java.lang.RuntimeException: canceled by user
	at com.sun.jnlp.DownloadServiceImpl$DefaultProgressImpl.progress(Unknown Source)
	at com.sun.jnlp.DownloadServiceImpl$ProgressHelper.(Unknown Source)
	at com.sun.jnlp.DownloadServiceImpl$6.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.jnlp.DownloadServiceImpl.loadPart(Unknown Source)
	at com.sun.jnlp.DownloadServiceImpl.loadPart(Unknown Source)
	at test.JWSCacheTest.run(JWSCacheTest.java:84)
	at java.lang.Thread.run(Unknown Source)
Part plant cached!
Part animal cached!
user cancelled action? ..proceed and try
DownloadServiceListener com.sun.jnlp.DownloadServiceImpl$DefaultProgressImpl@d9896e
Part art downloading!
java.lang.RuntimeException: canceled by user
	at com.sun.jnlp.DownloadServiceImpl$DefaultProgressImpl.progress(Unknown Source)
	at com.sun.jnlp.DownloadServiceImpl$ProgressHelper.(Unknown Source)
	at com.sun.jnlp.DownloadServiceImpl$6.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.jnlp.DownloadServiceImpl.loadPart(Unknown Source)
	at com.sun.jnlp.DownloadServiceImpl.loadPart(Unknown Source)
	at test.JWSCacheTest.run(JWSCacheTest.java:84)
	at java.lang.Thread.run(Unknown Source)
jar:http://www.physci.org/jws/cache/media/artmedia.jar!/image/scan0036-670x470.jpg
jar:http://www.physci.org/jws/cache/media/animalmedia.jar!/image/DCP_7940.jpg
jar:http://www.physci.org/jws/cache/media/plantmedia.jar!/image/100_1829-800x600.jpg
jar:http://www.physci.org/jws/cache/media/artmedia.jar!/image/scan0036-670x470.jpg

I am getting runtime exceptions 'cancelled by user', for any call after the 1st download (2nd call, 3rd call etc.) of each program run. On-screen, the dialog 'Verifying application' appears, while the console gets a stacktrace.

The odd thing is this example works as expected from the local file system! It is only the version running off the internet that has the 'cancelled by user' problem.

Other results

This example was also mentioned on the usenet newsgroup comp.lang.java.programmer on the thread WebStart caching test., here are the results.

Who Success OS Browser Java Notes
Andrew Thompson false Windows XP IE 6.0.2600 1.6.0-b105 The app. appeared on screen quickly, but threw exceptions for the second and all later downloads. Because of the code design, the dialog stayed on-screen, but the download proceeded and the image was available for load.
Andrew Thompson false Windows XP IE 6.0.2600 1.5.0_08 The app. took a long time to appear (over a minute), which suggested all the resources were being downloaded eagerly. However, it still threw exceptions for the second and all later downloads.
John T. false Windows FF ?  
Lew true Fedora Core 6 FF 5.0 Wait - didn't Lew mention 'no plug-in'? What's FF got to do with it? Should check.
Chris Uppal false Win. XP FF 1.5 1.6 Chris' latest post contains detailed info. on the problem. I have not yet had a chance, to review the results.
Dag Sunde true Win. XP IE 6.0 1.5.0_10  
Dag Sunde true Win. XP FF 2.0.0.1 1.5.0_10  
Dag Sunde true Win. XP SP2 Opera 9 1.5.0_10  
Patricia Shanahan true Win. XP SP2 FF 1.5.0.10 1.5.0_10-b03  

Download Example 6

The source, (current) media files and build script can be found in cache6.zip (903 KB).

Download and expand the archive, run the build script. The build file's default task launches the application off the local filesystem.

Example 7

Abandoned the default progress dialog in favor of a simpler 'home rolled' solution. This was largely for the purposes of testing whether I had made some incorrect assumptions in my earlier coding, and partly because I am sick of trying to make the default dialog work reliably.

Result 7

Initial testing locally, suggests the custom progress dialog appears, updates and disappears reliably.

Update! It was later discovered that the download might be so fast that the test condition of the download percentage reaching 100, used to set the dialog invisible, was never met. Or to put that the short way, for fast downloads, the dialog stayed on-screen.

Download Example 7

I never got around to uploading e.g. 7, which was found to be flawed in any case. See e.g. 8 download.

Example 8

Example 8 implements a simple and kludgy fix for the failure of the dialog to disappear, for fast downloads. Setting a 'past high percent' flag once the download reaches 95% complete, and watching for a later progress of '0' (the value returned after the download is complete) allows the code to know it can hide the dialog.

Result 8

Hooray! We seem to have sucess..

Download Example 8

The source, (current) media files and build script can be found in cache8.zip (<100 Kb, without the media).

References

It has been mentioned on the comp.lang.java.programmer usenet newsgroup under the title WebStart caching test

Also mentioned on the Sun forum for Java Web Start & JNLP as 'lazy' download test

© 2003-2010 by Andrew Thompson. All rights reserved.
Web hosting compliments of Java Web Hosting.
Java Web Hosting