?? simplemessageclient.java
字號:
/* * * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved. * * This software is the proprietary information of Sun Microsystems, Inc. * Use is subject to license terms. * */import javax.jms.*;import javax.naming.*;public class SimpleMessageClient { public static void main(String[] args) { Context jndiContext = null; QueueConnectionFactory queueConnectionFactory = null; QueueConnection queueConnection = null; QueueSession queueSession = null; Queue queue = null; QueueSender queueSender = null; TextMessage message = null; final int NUM_MSGS = 3; try { jndiContext = new InitialContext(); } catch (NamingException e) { System.out.println("Could not create JNDI " + "context: " + e.toString()); System.exit(1); } try { queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup ("java:comp/env/jms/MyQueueConnectionFactory"); queue = (Queue) jndiContext.lookup("java:comp/env/jms/QueueName"); } catch (NamingException e) { System.out.println("JNDI lookup failed: " + e.toString()); System.exit(1); } try { queueConnection = queueConnectionFactory.createQueueConnection(); queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); queueSender = queueSession.createSender(queue); message = queueSession.createTextMessage(); for (int i = 0; i < NUM_MSGS; i++) { message.setText("This is message " + (i + 1)); System.out.println("Sending message: " + message.getText()); queueSender.send(message); } } catch (JMSException e) { System.out.println("Exception occurred: " + e.toString()); } finally { if (queueConnection != null) { try { queueConnection.close(); } catch (JMSException e) {} } // if System.exit(0); } // finally } // main} // class
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -