我目前在 JBoss AS7 中遇到间歇性异常,不幸的是,我还无法重现。
我们目前正在运行两个应用程序,它们基本上设置为 JMS 消息的生产者/消费者。我们使用默认的 HornetQ 配置和 5 个 MDB 池。
两个应用程序都开始正常运行,按预期发送和接收消息。但过了一会儿,所有 MDB 都被锁定(它们每个都收到一条消息,但没有完成处理),JBoss 在此之后挂起一段时间,每十分钟显示以下消息:
[org.jboss.ejb3.invocation] (Thread-21081 (HornetQ-client-global-threads-1636833629)) JBAS014134: EJB Invocation failed on component MyMessageListener for method public abstract void javax.jms.MessageListener.onMessage(javax.jms.Message): javax.ejb.EJBException: JBAS014516: Failed to acquire a permit within 10 MINUTES
从 jarvana 中的 JBoss 代码来看,如果无法获取信号量,似乎会设置此错误:
/**
* Get an instance without identity.
* Can be used by finders,create-methods, and activation
*
* @return Context /w instance
*/
public T get() {
try {
boolean acquired = semaphore.tryAcquire(timeout, timeUnit);
if (!acquired)
throw new EJBException("Failed to acquire a permit within " + timeout + " " + timeUnit);
} catch (InterruptedException e) {
throw new EJBException("Acquire semaphore was interrupted");
}
...
问题是,为什么 MDB 会被锁定?他们不应该超时并继续处理吗?我在standalone.xml 文件中将超时设置为5 分钟,但它们似乎永远不会超时。
<session-bean>
<stateless>
<bean-instance-pool-ref pool-name="slsb-strict-max-pool"/>
</stateless>
<stateful default-access-timeout="5000" cache-ref="simple"/>
<singleton default-access-timeout="5000"/>
</session-bean>
有谁知道会发生什么?
我也很乐意接受任何关于如何模拟问题或其他设置 MDB 超时的方法的建议。
任何帮助,将不胜感激。
谢谢你的时间。
编辑:
因此,我终于能够通过简单地将 MessageListener 发送到比实例获取超时更长的时间来重现该问题。以下是测试代码:
<!-- standalone.xml -->
<strict-max-pool name="mdb-strict-max-pool" max-pool-size="5" instance-acquisition-timeout="30" instance-acquisition-timeout-unit="SECONDS"/>
多边开发银行:
@MessageDriven(name = "TestMDB", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/myQueue"),
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")//,
})
public class TestMDB implements MessageListener {
private final static Logger LOGGER = Logger.getLogger(TestMDB.class
.toString());
@Resource
private MessageDrivenContext ctx;
private final static int sleepingTime = MyProperties.SLEEP_MILLISECS;
/**
* @see MessageListener#onMessage(Message)
*/
public void onMessage(Message rcvMessage) {
ObjectMessage msg = null;
Future<String> future = null;
MyResource res = null;
try {
if (rcvMessage instanceof ObjectMessage) {
msg = (ObjectMessage) rcvMessage;
res = (MyResource)msg.getObject();
LOGGER.info("Received resource: " + res);
Thread.sleep(sleepingTime);
LOGGER.info("Released resource: " + res);
} else {
LOGGER.warning("Message of wrong type: "
+ rcvMessage.getClass().getName());
}
} catch (JMSException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}