1 Reply Latest reply on Sep 23, 2004 10:13 PM by Shigeru Chiba

    Wait for a program to run

    aquarius_kasuia Newbie

      Hi all. I have one problem:

      I´m using javassist in a program I´m developing, well to the point:

      I have a GUI, the users uses this GUI for some configurations and press the PLAY button. When the user press it I do this:

      //get the Default ClassPool
      javassist.ClassPool cp = javassist.ClassPool.getDefault();

      //Add the classpath of the system to the classpool
      for (int i = 0; i < vstringClassPath.length; i++)
      cp.appendClassPath(vstringClassPath);

      //Initialize a Loader and call the Controler
      javassist.reflect.Loader loader = new javassist.reflect.Loader();
      loader.setClassPool(cp);
      loader.main(new String[] {"Controler"});

      The Controler make some work with the paremeters the user has chosen and call the program the user has specified( I have a program that runs another program).

      The user program is not in the classpath that´s why I had to put the User´s ClassPath in the loader ClassPath.

      One of the things the Controler does is make some classes the user has chosen reflective.

      After that I run the user program. Code above:

      //Get the parent ClassLoader
      javassist.reflect.Loader loader = (javassist.reflect.Loader)Controler.class.getClassLoader();

      //Make the user´s class reflective
      for (int i = 0; i < classList.size(); i++)
      loader.makeReflective((String) classList.elementAt(i),
      "InjetorFis",
      "javassist.reflect.ClassMetaobject");

      //Run the system
      loader.run(mainClass, params);

      This works ok with almost everything.


      Now the problem: when the user has a program that creates another GUI the run method return after the GUI was created and my program terminate. I need it to stop there and wait the user to close his GUI.
      I have tried things with Threads but I couldn´t make it stop there.

      I hope I could explain my problem well.

      Thanks for your time, javassist is very good!! I hope someone can help me.

        • 1. Re: Wait for a program to run
          Shigeru Chiba Expert

          In general (with/without Javassist), the Java GUI is executed by a
          single thread dedicated for GUI. This thread is different from a thread
          running main().

          Since your program uses the GUI thread for running another user
          program, main() of that user program is also run by the same
          thread as GUI's. I guess that this configuration might confuse
          the GUI library.

          Your problem might be solved if the button-pressed listener
          starts a new thread, which executes Loader#run().

          I'm not sure that this way is correct but hope it helps.