Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4983013

# copies of SingleInstance application created when multiple files open/print

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 5.0
    • deploy
    • x86
    • windows_2000


      ###@###.### 2004-01-23

      J2SE Version (please include all output from java -version flag):
        java version "1.5.0-beta"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32)
        Java HotSpot(TM) Client VM (build 1.5.0-beta-b32, mixed mode)

      Does this problem occur on J2SE 1.4 or 1.4.1 or 1.4.2? Yes / No (pick one)
        No

      Operating System Configuration Information (be specific):
        Windows 2000 Professional Service Pack 2

      Hardware Configuration Information (be specific):
        Custom built Athlon 600MHz, TNT2 AGP, 384MB


      Bug Description:
        Selecting multiple files whose type has been associated with a Web Start
        application and then opening or printing them all at once can cause a
        variable number of instances of the application to be run if the application
        implements SingleInstanceListener and is not already running.


      Steps to Reproduce (be specific):


      1) Save SingleInstanceWSApp.jnlp (below) and edit the codebase to be the
         location at which it will be deployed.

      2) Save and compile SingleInstanceWSApp.java (below)
          javac -classpath javaws.jar SingleInstanceWSApp.java

      3) Jar up the classes
          jar -cvf SingleInstanceWSApp.jar *.class

      4) Deploy the .jnlp and .jar

      5) Run the application via the .jnlp, accepting the option to associate
         the file type

      6) Close the application (this is important)

      7) Create several files with the extension '.test' (10 seemed to
         illustrate it nicely on one particular machine), select them all within
         a file browser and execute the 'open' or 'print' command
         
      8) Observe that multiple copies of the SingleInstance application have
         been created, with the files distributed among them




      SingleInstanceWSApp.jnlp
      ========================

      <?xml version="1.0" encoding="utf-8"?>

      <jnlp spec="1.5" codebase="http://myserver/location">
          <information>
            <title>SingleInstanceWSApp</title>
            <vendor>Dodgy Apps</vendor>
            <association extensions="test" mime-type="text/x-test"/>
            <offline-allowed/>
          </information>
          <resources>
              <j2se version="1.3+"
      href="http://java.sun.com/products/autodl/j2se"/>
              <jar href="SingleInstanceWSApp.jar"/>
          </resources>
          <application-desc main-class="SingleInstanceWSApp">
              <argument>descriptor argument</argument>
          </application-desc>
      </jnlp>




      SingleInstanceWSApp.java
      ========================

      import java.util.*;
      import javax.jnlp.*;
      import javax.swing.*;
      import javax.swing.table.*;


      public class SingleInstanceWSApp extends JFrame implements
      SingleInstanceListener {

          public static void main(String[] args) {
              new SingleInstanceWSApp(args);
          }


          private ArgumentsTableModel tm;

          public SingleInstanceWSApp(String[] args) {

              tm = new ArgumentsTableModel();
              tm.addMethodCall("main", args);

              getContentPane().add(new JScrollPane(new JTable(tm)));

              setTitle("SingleInstanceWSApp");
              setSize(400,200);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              setVisible(true);

              try {
                  SingleInstanceService serv = (SingleInstanceService)
      ServiceManager.lookup("javax.jnlp.SingleInstanceService");
                  serv.addSingleInstanceListener(this);
              }
              catch (UnavailableServiceException ex) {
                  JOptionPane.showMessageDialog(this, "Unable to register as
      single instance : " + ex.getMessage());
              }
          }

          public void newActivation(String[] strings) {
              tm.addMethodCall("newActivation", strings);
          }


          static class ArgumentsTableModel extends AbstractTableModel {

              private List rowData = new ArrayList();

              public void addMethodCall(String methodName, String[] args) {

                  StringBuffer argData = new StringBuffer();
                  for (int i = 0; i < args.length; i++) {
                      if (i > 0) {
                          argData.append(", ");
                      }
                      argData.append('"').append(args[i]).append('"');
                  }

                  rowData.add(new String[] {methodName, argData.toString()});

                  fireTableRowsInserted(rowData.size(), rowData.size());
              }

              public int getRowCount() {
                  return rowData.size();
              }

              public int getColumnCount() {
                  return 2;
              }

              public String getColumnName(int index) {
                      return index == 0 ? "method" : "args";
              }

              public Object getValueAt(int rowIndex, int columnIndex) {
                  return ((String[]) rowData.get(rowIndex))[columnIndex];
              }
          }
      }






            ngthomas Thomas Ng (Inactive)
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: