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.
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?
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.
Independent Consultant — Author, EJB 3 in Action — Expert Group Member, Java EE 6 and EJB 3.1
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.
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop