Documentation

The Java™ Tutorials
Hide TOC
Avoiding Unnecessary Update Checks避免不必要的更新检查
Trail: Deployment
Lesson: Deployment In-Depth
Section: Deployment Best Practices

Avoiding Unnecessary Update Checks避免不必要的更新检查

Rich Internet applications (RIAs) are cached locally to improve startup time. 富互联网应用程序(RIA)在本地缓存,以缩短启动时间。However, before launching a RIA, the launch software checks to make sure that every JAR file referenced in the RIA's Java Network Launch Protocol (JNLP) file is up-to-date. 然而,在启动RIA之前,启动软件会检查以确保RIA的Java网络启动协议(JNLP)文件中引用的每个JAR文件都是最新的。In other words, the launch software makes sure that you are running the latest version of the RIA and not an older cached copy. 换句话说,启动软件确保您运行的是最新版本的RIA,而不是旧的缓存副本。These update checks can take up to a few hundred milliseconds depending on the number of JAR files and network speed. Use the techniques described in this topic to avoid unnecessary update checks and to enhance the start up time of your RIA.根据JAR文件的数量和网络速度,这些更新检查可能需要数百毫秒。使用本主题中描述的技术来避免不必要的更新检查,并提高RIA的启动时间。


Note: 

The term "launch software" is used here to collectively refer to the Java Plug-in software and the Java Web Start software. 这里使用的术语“启动软件”是指Java插件软件和Java Web Start软件的统称。The Java Plug-in software launches applets while the Java Web Start software launches Java Web Start applications.Java插件软件启动小程序,而Java Web Start软件启动Java Web Start应用程序。


Leveraging the Version Download Protocol利用版本下载协议

You can leverage the version download protocol to eliminate unnecessary version checks. 您可以利用版本下载协议来消除不必要的版本检查。See the following steps to enable this protocol.请参阅以下步骤以启用此协议。

  1. Rename the JAR files to include a version number suffix with the following naming convention:重命名JAR文件,使其包含具有以下命名约定的版本号后缀:
    <JAR file name>__V<version number>.jar
    For example, rename DynamicTreeDemo.jar to DynamicTreeDemo__V1.0.jar.例如,将DynamicTreeDemo.jar重命名为DynamicTreeDemo__V1.0.jar
  2. In the JNLP file, specify a version for every JAR file, and set the jnlp.versionEnabled property to true. 在JNLP文件中,为每个JAR文件指定一个版本,并将jnlp.versionEnabled属性设置为true
    <resources> <!-- Application Resources --> <j2se version="1.6+"
            href="http://java.sun.com/products/autodl/j2se"
                max-heap-size="128m" /> <jar href="DynamicTreeDemo.jar"
            main="true" version="1.0"/> <jar href="SomeOther.jar" version="2.0"/> <property name="jnlp.versionEnabled"
            value="true"/>
        <!-- ... -->
    </resources>

    When the jnlp.versionEnabled property is enabled, the launch software performs only one update check to make sure that the JNLP file is up-to-date. 启用jnlp.versionEnabled属性后,启动软件只执行一次更新检查,以确保JNLP文件是最新的。The software compares the version numbers that are specified in the JNLP file with the corresponding JAR file versions (according to the naming convention mentioned in step 1) and updates only the outdated JAR files. 软件将JNLP文件中指定的版本号与相应的JAR文件版本进行比较(根据步骤1中提到的命名约定),并仅更新过时的JAR文件。This approach is efficient because only the update check for the JNLP file occurs over the network. 这种方法非常有效,因为只有JNLP文件的更新检查通过网络进行。All other version checks occur locally.所有其他版本检查都在本地进行。

    If a file with the correct version number is not found, the launch software attempts to load the default JAR file (for example, DynamicTreeDemo.jar).如果找不到具有正确版本号的文件,则启动软件会尝试加载默认JAR文件(例如DynamicTreeDemo.jar)。

Performing Update Checks in the Background在后台执行更新检查

If it is not critical for the user to immediately run the latest version of your RIA, you can specify that all update checks should occur in the background. 如果用户不需要立即运行最新版本的RIA,则可以指定所有更新检查都应在后台进行。In this case, the launch software launches the locally cached copy for immediate usage and downloads a newer version of the RIA in the background. 在这种情况下,启动软件会启动本地缓存的副本以供立即使用,并在后台下载RIA的更新版本。The newer version of the RIA will be launched the next time the user attempts to use your RIA. 新版本的RIA将在用户下次尝试使用您的RIA时启动。To enable background update checks, add the following line to your JNLP file:要启用后台更新检查,请在JNLP文件中添加以下行:

<update check='background'/>

The following code snippet shows a sample JNLP file with the background update check enabled:下面的代码片段显示了启用后台更新检查的示例JNLP文件:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="" href=""> <information> <title>Applet Takes Params</title> <vendor>Dynamic Team</vendor> </information> <resources> <!-- Application Resources --> <j2se version="1.6+" href=
            "http://java.sun.com/products/autodl/j2se"/> <jar href="applet_AppletWithParameters.jar"
            main="true" /> </resources> <applet-desc
         name="Applet Takes Params"
         main-class="AppletTakesParams"
         width="800"
         height="50"> <param name="paramStr" value="someString"/> <param name="paramInt" value="22"/> </applet-desc> <update check="background"/>
</jnlp>

Previous page: Reducing the Download Time
Next page: Ensuring the Presence of the JRE Software