3 Replies Latest reply on Mar 25, 2004 10:50 AM by bherbert

    Starting/Executing a thread/process from EJB e.g Runtime.get

    mamta

      Hi

      I have a stateless session bean deployed in JBoss from which I want to execute ceratin Unix Commands.For this I am writing inside my EJB the following code:

      Runtime.getruntime().exec("mkdir directory",null,new File(workspace));
      Runtime.getruntime().exec("tar -xvf filename",null,new File(workspace));

      I have deployed this bean in JBoss.But erratically it gives error at runtime when the code gets called and exits in between.It gives either of the following exceptions:
      IllegalThreadStateException()
      InterruptedIOException()

      Since it is not recommended to start process from EJB,pls suggest an alternate solution to it.

      Regards,
      Mamta

        • 1. Re: Starting/Executing a thread/process from EJB e.g Runtime
          mamta

          Hi

          I have a stateless session bean deployed in JBoss from which I want to execute ceratin Unix Commands.For this I am writing inside my EJB the following code:

          Runtime.getruntime().exec("mkdir directory",null,new File(workspace));
          Runtime.getruntime().exec("tar -xvf filename",null,new File(workspace));

          I have deployed this bean in JBoss.But erratically it gives error at runtime when the code gets called and exits in between.It gives either of the following exceptions:
          IllegalThreadStateException()
          InterruptedIOException()

          Since it is not recommended to start process from EJB,pls suggest an alternate solution to it.

          Regards,
          Mamta

          • 2. Re: Starting/Executing a thread/process from EJB e.g Runtime

            Make directory:

            File f = new File("/path/to/directory");
            f.mkdirs();

            Untar:

            This is a little more difficult as tar is not support by Java out of the box. If your file was a zip (or a jar) then you could use the java.util.zip packages to unzip the file. As for tar either write you own tar file handler or find one off the web (The Apache Ant software has an implementation).


            Mike.

            • 3. Re: Starting/Executing a thread/process from EJB e.g Runtime
              bherbert

              why don't you write a shell script to create directory and tar. pass filename as an argument. Probably this issue suffice a single call to make all these things

              Cheers,
              B