• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Thread vs JMS Queue

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I�m new bee to JMS. I�ve a basic doubt. I have a Thread implementation in place which does a Job(some business logic), so that I can span n number of jobs simultaneously.

Thread Implementation:
PooledExecutor pool = new PooledExecutor(5);
for(int i=0;i<jobs.size();i++){
WorkFlowThread workFlowThread = new WorkFlowThread(jobs[i]);
pool.execute(workFlowThread);
}

JMS Implementation:

Context jmsCtx = new InitialContext();
QueueConnectionFactory qconFactory = (QueueConnectionFactory) jmsCtx.lookup("hydesJMSFactory");
QueueConnection qcon = qconFactory.createQueueConnection();
QueueSession qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) jmsCtx.lookup("HYDESQUEUE");
QueueSender qsender = qsession.createSender(queue);
ObjectMessage omessage = qsession.createObjectMessage();
omessage.setObject(new HydesQueueMessage(messageType, jobs));

What is the basic difference between Thread and JMS queue with respect to J2EE applications.
Do we benefit with JMS approach? I appreciate any help.

Thanks
Sruthi
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In short: Spawning new threads are bad in J2EE, sending to a queue is good. There's a ton of syntactical differences but what to keep in mind is that a queue is completely asynchronous listener that can get messages in any order, whereas a thread is still attached to the currently running process and has more direct access for synchronous calls.
 
Pay attention! Tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic