• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

EJB listening on a client socket for callbacks

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

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?
 
author & internet detective
Posts: 41151
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This sounds like what a Message Driven Bean would do. An MDB listens from messages on a queue and acts on them. The application server is handling the threads for you.
 
Adam Michalik
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 580
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Adam,

Creating threads is not that big of deal. You just have to be aware that the application server might not be able to scale as well since it won't have complete control over thread management.

Regards,
Reza
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Adam Michalik
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Reza Rahman
author
Posts: 580
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Adam,

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.

Regards,
Reza
 
Alok Kushwah
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic