File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Opening socket in stateless asynchronous ejb 3.1 in infinite loop. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Reply locked New topic

Opening socket in stateless asynchronous ejb 3.1 in infinite loop.

Manoj Kulkarni

Joined: Apr 30, 2012
Posts: 23

I have been reading that as per specs, EJB cannot be socket server listening on port. But I have question specific to EJB 3.1, because as per EJB3 expert group it is absolutely fine to open a serversocket to listen using EJB.
Just give your inputs on the below solution.

I create a stateless asynchronous EJB with NOT_SUPPORTED transaction attribute. In that method I used a method local variable to initiate a server socket.
I now have a while(true) loop which keeps on listening on the socket to read the message and process it and reply back.

What is wrong with this? Because as per my analysis.

There is no problem of passivation, because EJB will always be active in container till while(true) loop is broken and serversocket object is method local, so it does not clash with ejbcontext.
There is no concern of client because it is asynchronous EJB so there is no client waiting for ejb method to complete it's task
There is no problem with transaction or it's timeout because it is NOT_SUPPORTED

Let me know if there are any problems with this design and what are those?
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 9955

Closing this one. Please continue the discussion in the other thread you created

[My Blog] [JavaRanch Journal]
It is sorta covered in the JavaRanch Style Guide.
subject: Opening socket in stateless asynchronous ejb 3.1 in infinite loop.
Similar Threads
socket access from ejb
Handle a ServerSocket in an EJB3-powered webapp
"Socket is closed"... why?
Doubt in Maxs' Socket solution
server socket and accept call