aspose file tools*
The moose likes Spring and the fly likes JmsTemplate.receiveAndConvert() times out if another thread is mid-transaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "JmsTemplate.receiveAndConvert() times out if another thread is mid-transaction" Watch "JmsTemplate.receiveAndConvert() times out if another thread is mid-transaction" New topic
Author

JmsTemplate.receiveAndConvert() times out if another thread is mid-transaction

PaulN Pearson
Greenhorn

Joined: May 23, 2008
Posts: 12
We have an application which reads messages from a JMS queue in a multithreaded scenario using Spring. Simplified version of our Runnable.run() method, being executed by two threads, is as follows:



The problem we're seeing is that, sometimes, if one of the threads is between the getTransaction() (line 8) and commit() (line 21) calls (eg if the call to ingest(putTask) is taking a long time), the second thread will continually timeout while calling receiveAndConvert(), and return null, even if there are other messages waiting on the queue. The behaviour is not consistent, however, and sometimes the next message can be read regardless. I *can* get consistent behaviour (timing out and returning null) by running Eclipse in debug mode though. Does anyone know what we're doing wrong? Or is this a bug? I realise I've missed out some (irrelevant) methods, the field declarations, and the application context. If any of these are needed for someone to provide help I will happily post them.

Thanks,
Paul
PaulN Pearson
Greenhorn

Joined: May 23, 2008
Posts: 12
Aha, I've just found I can prevent this behaviour by changing the queuePrefetch value on the PrefetchPolicy of my ConnectionFactory from 1 to 0. What I don't understand is why the prefetch behaviour only comes into effect when I'm using transactions though. Also, if thread 1 has read a message (and presumably prefetched the next), I can pause this thread after it's transaction has been commited, and get thread 2 to read the second message instead. My understanding was that a prefetch policy greater than 0 would mean thread 1 would pre-allocate the two messages for itself and thread 2 wouldn't be able to consume either...?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JmsTemplate.receiveAndConvert() times out if another thread is mid-transaction
 
Similar Threads
Shutting down a thread instantly - should this work?
WAS 5.0 : XA datasource(9i) in a UserTransaction throws an error
Permission denied exception on saving file to filesystem
MDB Poison message
ServletContextListener & Threads