[
https://issues.jboss.org/browse/ISPN-10138?page=com.atlassian.jira.plugin...
]
Dan Berindei commented on ISPN-10138:
-------------------------------------
Can you reproduce the problem with a small application and attach it here? The code in the
description doesn't seem Infinispan-related at all.
My guess would be that when you register a listener in JMS, JMS uses the thread context
classloader to deserialize messages. {{CompletableFuture.runAsync()}} runs your code on a
{{ForkJoinPool.commonPool()}} thread, which is not managed by the application service and
doesn't have a proper thread context classloader. The first application to call
{{CompletableFuture.runAsync()}} creates a common-pool thread with its classloader set as
the thread-context classloader, and the 2nd application to call
{{CompletableFuture.runAsync()}} reuses the thread with the wrong thread-context
classloader. When the applications start in parallel, each of them gets its own
common-pool thread, so they have the proper thread-context classloader.
JMS ClassCastException
----------------------
Key: ISPN-10138
URL:
https://issues.jboss.org/browse/ISPN-10138
Project: Infinispan
Issue Type: Bug
Components: Listeners
Affects Versions: 9.4.4.Final
Environment: JBoss 6.4.10.GA
Infinispan 9.4.4.FINAL
hornetq 2.3.25.FINAL
jdk 1.8.0_92
Reporter: worldline_ge_dev worldline_ge_dev
Priority: Minor
We have a malfunction that we think is a bug but are not sure whether it is a JBoss,
HornetQ or Infinspan issue. Here is the situation:
Two war applications on one JBoss, one sends data into a JMS queue, the other consumes
them. On startup, each application registers in a replicated Infinispan cache.
Infinispan subsystem is excluded in jboss-deployment-structure.xml and libs are in the
lib folder of the applications. When we start JBoss and both applications are deployed
simultaneously,
all is okay. When first the consuming app is deployed and then the sending app we observe
following error in last line of the following code in MessageListener:
{code:java}
public void process(Message inMessage) {
DistributionMetadata metadata = null;
log.info("DistributionMetadata.class.getClassLoader().toString(): " +
DistributionMetadata.class.getClassLoader().toString());
try {
Object obj = ((ObjectMessage) inMessage).getObject();
log.info("obj.getClass().getClassLoader().toString(): " +
obj.getClass().getClassLoader().toString());
metadata = (DistributionMetadata) obj;
{code}
INFO 12:01:41,805 (Thread-9 (HornetQ-client-global-threads-1054694434))
(JmsConsumer.java:process:214) -
DistributionMetadata.class.getClassLoader().toString(): ModuleClassLoader for Module
"deployment.msp.war:main" from Service Module Loader
obj.getClass().getClassLoader().toString(): ModuleClassLoader for Module
"deployment.bvn-idx-routing.war:main" from Service Module Loader
ERROR 12:01:41,805 (Thread-9 (HornetQ-client-global-threads-1054694434))
(JmsConsumer.java:process:244) -FAILED:
com.equensworldline.jms.entities.DistributionMetadata cannot be cast to
com.equensworldline.jms.entities.DistributionMetadata: java.lang.ClassCastException:
com.equensworldline.jms.entities.DistributionMetadata cannot be cast to
com.equensworldline.jms.entities.DistributionMetadata
at com.equensworldline.jms.api.external.JmsConsumer.process(JmsConsumer.java:217)
at
com.equensworldline.correlationidmgmt.jee.CorrelationIDMessageListener.onMessage(CorrelationIDMessageListener.java:32)
at
org.hornetq.jms.client.JMSMessageListenerWrapper.onMessage(JMSMessageListenerWrapper.java:100)
at
org.hornetq.core.client.impl.ClientConsumerImpl.callOnMessage(ClientConsumerImpl.java:1123)
at
org.hornetq.core.client.impl.ClientConsumerImpl.access$500(ClientConsumerImpl.java:57)
at
org.hornetq.core.client.impl.ClientConsumerImpl$Runner.run(ClientConsumerImpl.java:1258)
at
org.hornetq.utils.OrderedExecutorFactory$OrderedExecutor$1.run(OrderedExecutorFactory.java:105)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
You see the DistributionMetadata class is loaded by two different classloaders which
causes this error.
The remedy we found is very strange and has on first sight nothing to do with the
failure:
We have registered an Infinispan cachelistener and within the @CacheEntryCreated event we
start a JMS listener and access the cache. Because we observed
org.infinispan.util.concurrent.TimeoutException
we make this asynchronously following the advice in
[
https://developer.jboss.org/thread/268919|https://developer.jboss.org/thr...].
{code:java}
CompletableFuture.runAsync(() -> regService.startListener(event.getValue()));
{code}
When we change back to a synchronous call, everything works and the ClassCastException
does not occur. It seems, either Infinispan, HornetQ or JBoss does something queer with
the classloaders in the described situation
--
This message was sent by Atlassian Jira
(v7.12.1#712002)