For messaging system/ handling message - use MDB; don't use Entity Bean or Session Bean. Please provide me the reason.
Thanks in Adv
RW
An MDB is designed to accept messages whereas the others aren't. From an old Sun tutorial but still the same in the up to date version
The most visible difference between message-driven beans and session
and entity beans is that clients do not access message-driven beans
through interfaces. Interfaces are described in the section Defining
Client Access with Interfaces. Unlike a session or entity bean, a
message-driven bean has only a bean class
and
Session beans allow you to send JMS messages and to receive them
synchronously but not asynchronously. To avoid tying up server
resources, do not to use blocking synchronous receives in a
server-side component; in general, JMS messages should not be sent or
received synchronously. To receive messages asynchronously, use a
message-driven bean.
In other words: in a Session bean you can only receive a message when the bean was called. The app server will automatically call the onMessage method of the MDB attached to the destination (Queue or Topic) on which a message was received. This means that MDBs will be guaranteed to handle each message as soon it's available, something that you can't guarantee with session beans.
Related
In the EJB 3.1, we have annotated a method with #Asynchronous and using Future.get to fetch the results.
Question is when we do future.get(), does the database connections from the connection pool and resources are released which was being used in that async method?
Database connections are closed according to your configured connection pooling policy of the used application server.
When talking about session beans and container managed transactions, the connection is returned at the end to the transaction scope of the called business method.
Since session beans with #Asynchronous annotations do not support transaction propagation (e.g. see EJB 3.2 spec 4.5.3), a new transaction is created with every call to a business method if the method is configured with REQUIRED or REQUIRES_NEW. Thus, this transaction scope ends with the called business method returning.
There is a chance they are :) Otherwise using #Asynchronous would quickly lead to application crash due to lack of resources...
Anyway as resources are stored using Thread Local storage in Java-ee and as #Asynchronous defer the execution to a dedicated thread, the resources used there (including JCA Connection - and so database one) are also dedicated to the #Asynchronous method execution (not inherited from the caller thread).
Hello everybody I am newbie for EJB component technology and i have to learn this in order to prepare my colloquium exam. I am not sure I can understand all details of the life cycle.
The life cycle includes these steps:
-The client request to EJB Container ( but how this request could be done ? Is the location of the request I mean that remote " outside of the EJB container" or local" inside of the EJB container" is important or not?)
-By depending on the request one bean instance is created in the pool and return to the client and after use from the client it returns again in the pool ( depending on the bean type(?).
I think this scenario appropriate for the stateless session bean but I am not sure. Because in stateful session bean scenario there is no pool.)
Advance thanks for all helps.
"client" in this context just means "application code that will lookup/inject an EJB and call EJBs"; it is the opposite of "application code of the EJB itself" (which does not have a well-defined term; I've seen the term "EJB" overloaded for this meaning, or "service", etc.). Local EJB vs remote EJB is not relevant in this context, even though "client" also has a well-defined meaning for remote.
Yes, pooling of session beans refers only to stateless session beans. Stateful and singleton session beans do not have a pool. Message-driven beans can also be pooled, but they are not directly invoked by a client per se, even though there can be a logical client; e.g., the one that send the JMS message. (Entity beans can also be pooled, but they're not really relevant these days.)
I have a logging bean where I log how long database calls and bean method calls take via interceptors.
I have a bean that calls two #Asynchronous methods. Those two #Asynchronous methods call the database and are intercepted.
When the logging bean logs though, it appears that the database has taken 0 ms which can't be right. When I use this logging bean and all the interceptors without #Asynchronous calls everything works fine.
I'm using glassfish 3.1.2.2. The doc http://glassfish.java.net/nonav/docs/v3/api/javax/enterprise/context/RequestScoped.html says "The request context is destroyed: after the asynchronous observer notification completes," Does that mean that my logging bean instance in the #Asynchronous method is destroyed when the method completes? What can I use to accomplish my goal?
There are multiple layers:
A CDI proxy, which runs CDI interceptors and then calls the EJB.
An EJB proxy, which schedules async work and returns immediately.
EJB interceptors, which run on the async thread.
Presumably, you're using a CDI interceptor, which is measuring the time it takes for the EJB container to schedule the async work. If you switch to using an EJB interceptor instead (i.e., annotate the EJB method with #Interceptors), then you can measure the time taken to execute the work.
I have a #Stateful EJB annotated as #ConversationScoped. The client (JSF) makes a request to my EJB which: starts the conversation - conversation.begin(), do something and shows the response to the client.
The client then makes another request, the EJB does something and closes the conversation - conversation.end().
Is the #Stateful EJB removed after the conversation end? Or do I have to explicitly call #Remove?
The CDI specs say that the scoped EJBs are automatically created and destroyed when the scope is created or destroyed. The same is true for the Conversation scope. So, you should not try to call a #Remove method.
http://docs.jboss.org/cdi/spec/1.0/html/concepts.html#d0e1066
Our flex client needs to invoke server side EJB3 session bean. For each module we have seperate session bean.
Whether it is best to have separate flex end point (remote object) to each session bean to invoke methods or to create a single facade session bean as an endpoint and invoke other session bean methods through this facade bean.
Whether creating multiple flex end points increases the performance or its an expensive process?
Creating a RemoteObject is not an expensive process but having many of them won't really increase client-side performance either. Typically all of your RemoteObjects will reference a shared ChannelSet which basically represents the connection to the server endpoint. I would recommend using one RemoteObject for each session bean you have. You can relate a RemoteObject to a session bean by specifying the "destination" property on the RemoteObject and ensuring that your server side implementation of the FlexFactory interface resolves the destination name to the appropriate session bean.