2 Replies Latest reply on Jun 22, 2006 7:39 AM by keith1

    Using an MBean to spawn native Process with JBoss AS/4.03 an

    keith1

      Hi,

      I'm running JBoss AS 4.03 to perform some simulation work. I've got an MBean which spawns off various threads. Each thread in turn calls java.lang.Runtime.exec() to create a native process. Invocation of this works find. I can create processes all day long and interrupt my threads. However, if I call destroy() on a Process, which was created by a thread, held by the mbean, the JBoss AS shutdown hook is abruptly called and everything ends with:

      [exec] 15:45:50,433 INFO [Server] Runtime shutdown hook called, forceHalt: true
      [exec] 15:45:50,433 INFO [Server] JBoss SHUTDOWN: Undeploying all packages


      Questions:
      1. Is is ok (or at least permitted) to spawn threads and native Process objects from an MBean?
      2. How does one go about forcefully destroying a spawned Process without killing the application server?

      I would hate to move my process handling to a separate JVM outside of JBoss. Any suggestions?

      Thanks,
      Keith

        • 1. Re: Using an MBean to spawn native Process with JBoss AS/4.0
          dimitris

          1. Not stricly spec compliant (if talking about EJBs), but Ok
          2. Don't know. If you can have a look, for the jboss web project, mladen made a wrapper library on top of apr (apache portable runtime) which may have better process control.

          Let us know of your findings anyway. I'd be glad to incorporate a general purpose process handling mbean to jboss.

          • 2. Re: Using an MBean to spawn native Process with JBoss AS/4.0
            keith1

            Just as an update, I was able to find a solution to the problem. In order to spawn a native Process from an MBean required 3 threads and a signal handler. One thread handled the exec() and destroy() of the Process and implemented a signal handler to catch SIGTERM. The other two threads were typical stdout/stderr consumers to grab the output of the Process.

            The key to the resolution was the introduction of a signal handler. I thought JBoss AS would object, but it seemed to work fine. I can either call Process.destroy() and kill the spawned process without affecting JBoss, or externally just "kill -9" the PID of the process without affecting JBoss. The signal handler for the thread which exec'd the Process catches the SIGTERM and my JBoss AS no longer exits with a sudden shutdown hook call.

            Thanks for the feedback.

            Regards,
            Keith