wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Java Thread vs JMS Queue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Java Thread vs JMS Queue" Watch "Java Thread vs JMS Queue" New topic
Author

Java Thread vs JMS Queue

sruthi adhuri
Greenhorn

Joined: Nov 19, 2005
Posts: 9
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
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3702
    
    5

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.


My Blog: Down Home Country Coding with Scott Selikoff
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Thread vs JMS Queue
 
Similar Threads
Trying to write a jms client to receive as message
JMS Client not working in JSP
java.lang.NoSuchMethodError: getMessageData
P2P using WSAD's embedded JMS- Naming Exception
javax .naming. ConfigurationException: