Execute subprocesses in JavaEE 6

怎甘沉沦 提交于 2019-12-05 03:42:09

问题


I'm trying to execute subprocesses from within my application server (Glassfish 3.1.2)

Therefore I discovered the Apache Commons Exec library. The problem is that this library creates threads which should not be done on an application server because the server is not aware of these threads.
What could be a solution to this problem?

Would it be possible to create a message component written in Java SE who consumes messages containing information about pending jobs and register it with the application server?

The application server would then not have to deal with runtime exceptions and threads but just consume messages which contain the result or an exception.

Do you have any better ideas?


回答1:


You could either use:

  • MDB (as pointed by duffymo),
  • Servlets 3.0 asynchronous processing,
  • Asynchronous EJB invocation.

Effectively, it should give you similar functionality as plain subprocesses.

Using Java SE component which communicates with Java EE just to overcome using threads on your own sounds a bit like an overkill. Just read about mentioned solutions and try if any of them fits your needs.




回答2:


Message driven beans were designed for asynchronous processing. It could be a solution to your problem. You can create a separate listener thread pool sized to handle the traffic.



来源:https://stackoverflow.com/questions/12601696/execute-subprocesses-in-javaee-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!