I stumbled across a following problem:
1) An EJB opens a client socket to a (non-Java EE) server
2) The EJB should asynchronously receive messages from the server
The idea in "standard Java" would be to construct the EJB object, start a new thread, in that thread open a socket and put the incoming messages to some queue. The EJB then gets the messages from the queue for processing.
But Java EE forbids creating new threads. Do you have any ideas how to solve the problem?
Surely it is a problem easily solved by a MDB, but only if the server could send JMS messages... Unfortunately the third-party non-Java server does not support that, only raw socket connections are available.
If client on other hand can send data only on raw socket then go ahead a create a server socket and listen to that socket and create a slave thread for each connection/request to serve the request. The slave thread can call EJB directly (synchronouse) or send JMS messge (asynchronous) for further processing.
Don't create your own thread in ejb. Don't manage threads in EJB.
Joined: Feb 18, 2008
Thanks for the replies!
I think I'll stick to the spec and will not tinker with thread management on the server. I thought about a standalone mini-app talking to the remote server and forwarding the messages via JMS to the EJB. But I came across technologies like resource adapters and connectors - does that sound applicable to you?
Joined: Feb 01, 2005
Not saying one way or the other, but just to make sure, the spec does not forbid thread managemt, it discourage them. I've actually specifically talked with some vendors about this. Without going into great detail, it's more about SLA aggreements for an application server rather than a serious technical concern.
Just food for thought/options to consider.
Joined: Jul 10, 2007
EJB spec says that enterprise bean must not attempt to listen on a socket, so no server socket is allowed in EJB. But you can open client socket to connect to server socket. However socket must be closed when the ejb is passivated. Socket connection must be established when the ejb is activated.
I will suggets avoid opening any type of socket in EJB.
subject: EJB listening on a client socket for callbacks