An EJB singleton as TCP server
I have an EJB, and a web service using it. I would now like to write a simple TCP server as an alternative to the webservice, but I dont want to rewrite the logic in the EJB and the database layer beneath it.
So I wrote a simple TCP server as a singleton and annotated it @Startup. The application works but it also seems to kill the JBoss administration console aswell as produce a slew of timeout exceptions. I suspect the cause is the infinite while loop I have in the server bean, which is required to accept incoming connections. Is there a way around this or is simply a bad idea to have an EJB as the server?
I guess the alt开发者_C百科ernative is to write a standalone java app and use a remote interface on my business logic EJB, though it seems a bit of a hassle....
I think you have 2 solutions.
You can write stand alone demon that is a simple TCP server. It should listen to the port and call your EJB layer running into JBoss when it need.
alternatively you can implement your server using JCA connector. Theoretically it is "right" solution. And it is not so hard if you use it for incoming connections only.
精彩评论