[Messaging, JMS & JBossMQ] - Re: Bug: Injected EJB objects instantiated on every MDB call
by jaikiran
I do see the same behaviour on 4.2.2. Here's my MDB:
package org.myapp.ejb.impl;
|
| import javax.ejb.ActivationConfigProperty;
| import javax.ejb.EJB;
| import javax.ejb.MessageDriven;
| import javax.jms.Message;
| import javax.jms.MessageListener;
| import javax.persistence.PostRemove;
|
| import org.apache.log4j.Logger;
| import org.myapp.ejb.UserManager;
|
| /**
| * MDB for testing injection of EJBs
| *
| * @author Jaikiran Pai
| * @since
| */
| @MessageDriven(activationConfig =
| {
| @ActivationConfigProperty(propertyName="destinationType",
| propertyValue="javax.jms.Queue"),
| @ActivationConfigProperty(propertyName="destination",
| propertyValue="queue/A")
| })
| public class MyMDB implements MessageListener {
|
| private static Logger logger = Logger.getLogger(MyMDB.class);
|
|
| private UserManager userManager;
|
| public UserManager getUserManager() {
| return this.userManager;
| }
|
| @EJB
| public void setUserManager(UserManager userManager) {
| this.userManager = userManager;
| }
|
| /**
| * Default constructor
| *
| */
| public MyMDB() {
| System.out.println("In constructor of MDB");
| }
|
| /**
| *
| */
| public void onMessage(Message arg0) {
| System.out.println("onMessage of MyMDB called");
| System.out.println("EJB is " + getUserManager());
| getUserManager().getUser((long)1);
| logger.info("onMessage of MyMDB called");
| }
|
|
|
| }
A new instance of UserManagerBean gets injected everytime the onMessage method is invoked. I just glanced through the EJB spec and did not see any mention of this behaviour being mandated. You are right, the injection should have happened only if a new instance of the MDB was created instead of injecting the EJB on every call of onMessage.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4139296#4139296
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4139296
18 years
[Installation, Configuration & DEPLOYMENT] - Re: 5.0.0.Beta4 startup performance problem
by gcoleman
I can cut the startup time to about 5mins by changing org.jboss.ejb3.dependency.EjbLinkDemandMetaData with the following patch.
I stole some code from the ObjectName constructor. It's quick, dirty and not production quality but proves the point that relying on Exceptions for flow control is a bad idea.
| Index: EjbLinkDemandMetaData.java
|
| ===================================================================
|
| --- EjbLinkDemandMetaData.java (revision 71344)
|
| +++ EjbLinkDemandMetaData.java (working copy)
|
| @@ -45,7 +45,7 @@
|
| * specified.
| *
| * @author <a href="mailto:carlo.dewolf@jboss.com">Carlo de Wolf</a>
| - * @version $Revision: $
| + * @version $Revision$
| */
| public class EjbLinkDemandMetaData extends JBossObject
| implements DemandMetaData, Serializable
| @@ -129,9 +129,13 @@
|
| {
| for(ControllerContext context : controller.getContextsByState(ControllerState.INSTALLED))
| {
| - try
| - {
| - ObjectName otherName = new ObjectName(context.getName().toString());
| +
| + String otherNameStr = context.getName().toString();
| + if (isValidName(otherNameStr))
| + {
| + try
| + {
| + ObjectName otherName = new ObjectName(otherNameStr);
|
| if(demand.apply(otherName))
| {
| @@ -144,12 +148,63 @@
|
| catch (MalformedObjectNameException e)
| {
| // ignore this context
| + System.out.println("MalformedObjectNameException constructing ObjectName for " + context.getName().toString());
| }
| + }
| }
| setResolved(false);
| return isResolved();
| }
| -
| +
| + private boolean isValidName(String name) {
| +
| + // The name cannot be null
| + if (name == null)
| + return false;
| +
| + if (name.startsWith("vfsfile:/"))
| + return false;
| +
| + if (name.startsWith("java:comp/"))
| + return false;
| +
| + // Test if the name is empty
| + if (name.length() == 0) {
| + return true;
| + }
| +
| + // initialize parsing of the string
| + char[] name_chars = name.toCharArray();
| + int len = name_chars.length;
| + // length at most
| + int index = 0;
| +
| + domain_parsing:
| + while (index < len) {
| + switch (name_chars[index]) {
| + case ':' :
| + break domain_parsing;
| + case '=' :
| + int i = ++index;
| + while ((i < len) && (name_chars[i++] != ':'))
| + if (i == len)
| + return false;
| + break;
| + case '\n' :
| + return false;
| + case '*' :
| + case '?' :
| +
| + default :
| + index++;
| + }
| + }
| +
| + // check for non-empty properties
| + return (index != len);
| + }
| +
| +
| @Override
| public void toString(JBossStringBuilder buffer)
| {
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4139281#4139281
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4139281
18 years