Search code examples
javaprocessejbspecificationsspawn

Can an EJB spawn an operating system process?


Can an EJB start an operating system process, using either ProcessBuilder or Runtime.exec?

The EJB 3.2 Core Specification states that an enterprise bean must not attempt to:

  • manage threads
  • directly read or write a file descriptor
  • load a native library

But it does not explicitly forbid an enterprise bean from spawning operating system processes.


Solution

  • You can do all those things but the reason for these restrictions is that the container can span over multiple JVM’s on different platforms and may create an ejb in any of these. The listed things are those things that the application server does not maintain so you risk your jvm is different than expected when your ejb runs.

    If you know this won’t be a problem you can do what you want

    Note that recent versions of the JEE specification provides a backend process api. I would look into that.