0

I was playing a little bit with Vysper, embedding it into a Java EE web application in TomEE. Vysper is an alpha/beta version of a XMPP server based on Apache Mina that can be easily embedded into java applications. I could sucessfully instantiate a Vysper instance into a @Startup / @Singleton scoped bean. So far so good. It seems to work ok when I run it in a vanilla TomEE instance from inside eclipse.

But then I've remembered that Java EE applications should not use threads (see this answer at stack overflow - Why is spawning threads in Java EE container discouraged?). If I remember well, there are even wrappers for threads when someone need to run such a thing from inside a Java EE app.

I know that TomEE+ uses Quartz and ActiveMQ as backend to implement several Java EE services, but they're part of the container, not part of the web application.

I bet Mina and Vysper use threads internally, so I wonder it's not a good idea to embed Vysper directly into a Java EE web application in this context. Of course, I could just run the XMPP server as another component of the system, outside the container, which would also make more sense in a clustered deployment.

But supposing I am running in a standalone deployment (single TomEE), running an embedded Vysper into a Java EE web application could be harmful because it relies internally on threads? If it's not, why?

4

1 回答 1

1

有些事情是被禁止的,但它越来越不严格,而且 tomee(和大多数 EE 服务器)不会强加它,否则你几乎无能为力。

你唯一能得到的惊喜是期望被管理(安全、CDI、...),因为这不是容器线程,所以你不是。如果你接受这个游戏规则,那么没有问题。

PS:不要忘记正确关闭线程

于 2014-09-11T21:20:12.340 回答