Which will correctly obtain a connection factory for a queue?

You are writing an EE component that functions as a message producer. The message producer
sends message to a JMS queue. The component environment defines a resource-ref of type
javax.jms.ConnectionFactory with the same jms/ConnectionFactory.
Which will correctly obtain a connection factory for a queue?

You are writing an EE component that functions as a message producer. The message producer
sends message to a JMS queue. The component environment defines a resource-ref of type
javax.jms.ConnectionFactory with the same jms/ConnectionFactory.
Which will correctly obtain a connection factory for a queue?

A.
Context context = new initialContext();
Connectionfactory confac = (ConnectionFactory) Context.lookup
(�java: comp/env/jms/ConnectionFactory�);

B.
InitialContext Context = new Context () ;
QueueConnectionFactory confac = (QueueConnectionFactory) context.lookup
(�java: comp/env/jms/Myfactory�);

C.
@Resource (�ConnectionFactory�)
private static QueueConnectionFactory confac;

D.
@Resource (loopkup = �jms/QueueConnectionFactory�)
private static ConnectionFactoryconfac;

Explanation:
A connection factory is the object a client uses to create a connection to a
provider. A connection factory encapsulates a set of connection configuration parameters that has
been defined by an administrator. Each connection factory is an instance of
theConnectionFactory, QueueConnectionFactory, or TopicConnectionFactory interface
At the beginning of a JMS client program, you usually inject a connection factory resource into a
ConnectionFactory object. For example, the following code fragment specifies a resource whose
JNDI name is jms/ConnectionFactory and assigns it to a ConnectionFactory object:
@Resource(lookup = “jms/ConnectionFactory”)

private static ConnectionFactory connectionFactory;
Reference: The Java EE 6 Tutoria, The JMS API Programming Model



Leave a Reply 6

Your email address will not be published. Required fields are marked *


Alex

Alex

D: Cannot be static. So as Marian said, A.

MG

MG

A is correct answer.

ConnectionFactory can be static, but in question D defined jndi name jms/ConnectionFactory and not jms/QueueConnectionFactory as proposes in answer D.

JavaBatman

JavaBatman

B is correct one