EJB's and Threading

前端 未结 4 908
醉话见心
醉话见心 2021-02-06 08:55

From what I understand it is illegal to spawn threads from within an EJB as it may potentially interfere with the EJB\'s lifecycle. However, is it illegal to use predefined Java

4条回答
  •  余生分开走
    2021-02-06 09:12

    To add to @Charlie Martin's answer, whatever you need the Executor to do, you could design another EJB to perform the same action without the Executor. This allows the new EJB to run in a separate thread handled by the container. The downside is you might have to "reimplement the wheel" since you still do not want to use threads/Executor from the JVM. It also adds to the overhead of getting one EJB to locate/request/connect/call another.

    The bottom line is that EJBs are supposed to be worker threads themselves. It may seem like overkill to replicate code instead of use the Executor and it is up to a point. The biggest distinction is one of scale. Executors will be limited to a single JVM while EJBs can be scaled across JVMs and across servers.

提交回复
热议问题