⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jms6.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 5 页
字号:
</p><a name="wp83823"> </a><p class="pBody">The program contains five classes: <code class="cCode">Retailer</code>, <code class="cCode">Vendor</code>, <code class="cCode">GenericSupplier</code>, <code class="cCode">VendorMessageListener</code>, and <code class="cCode">Order</code>. The program also contains a main method and a method that runs the threads of the <code class="cCode">Retail</code>, <code class="cCode">Vendor</code>, and two supplier classes.</p><a name="wp83824"> </a><p class="pBody">All the messages use the <code class="cCode">MapMessage</code> message type. Synchronous receives are used for all message reception except for the case of the vendor processing the replies of the suppliers. These replies are processed asynchronously and demonstrate how to use transactions within a message listener.</p><a name="wp83825"> </a><p class="pBody">At random intervals, the <code class="cCode">Vendor</code> class throws an exception to simulate a database problem and cause a rollback.</p><a name="wp83826"> </a><p class="pBody">All classes except <code class="cCode">Retailer</code> use transacted sessions.</p><a name="wp83827"> </a><p class="pBody">The program uses three queues named <code class="cCode">AQueue</code>, <code class="cCode">BQueue</code>, and <code class="cCode">CQueue</code>, and one topic named <code class="cCode">OTopic</code>. Before you run the program, </p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp88165"> </a><div class="pSmartList1"><li>Compile the program if you did not do so previously:</li></div><a name="wp88166"> </a><p class="pBodyRelative"><code class="cCode">asant build</code></p><a name="wp97237"> </a><div class="pSmartList1"><li>In the Admin Console, create three physical destinations of type <code class="cCode">queue</code> named <code class="cCode">AQueueP</code>, <code class="cCode">BQueueP</code>, and <code class="cCode">CQueueP</code>.</li></div><a name="wp97277"> </a><div class="pSmartList1"><li>Create a physical destination of type <code class="cCode">topic</code> named <code class="cCode">OTopicP</code>.</li></div><a name="wp97238"> </a><div class="pSmartList1"><li>Create three destination resources with the names <code class="cCode">AQueue</code>, <code class="cCode">BQueue</code>, and <code class="cCode">CQueue</code>, all of type <code class="cCode">javax.jms.Queue</code>. For each, add the property <code class="cCode">Name</code> with the value <code class="cCode">AQueueP</code>, <code class="cCode">BQueueP</code>, or <code class="cCode">CQueueP</code>, respectively.</li></div><a name="wp97261"> </a><div class="pSmartList1"><li>Create a destination resource with the name <code class="cCode">OTopic</code> of type <code class="cCode">javax.jms.Topic</code>. Add the property <code class="cCode">Name</code> with the value <code class="cCode">OTopicP</code>.</li></div></ol></div><a name="wp97262"> </a><p class="pBody">To package the program, perform the following steps:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp92962"> </a><div class="pSmartList1"><li>If you did not do so before, start <code class="cCode">deploytool</code>.</li></div><a name="wp92963"> </a><div class="pSmartList1"><li>Choose File<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>New<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Application Client to start the Application Client Wizard.</li></div><a name="wp92964"> </a><div class="pSmartList1"><li>Select the radio button labeled Create New Stand-Alone AppClient Module.</li></div><a name="wp92965"> </a><div class="pSmartList1"><li>Click Browse next to the AppClient Location field and navigate to the <code class="cCode">&lt;</code><code class="cVariable">INSTALL</code><code class="cCode">&gt;/j2eetutorial14/examples/jms/advanced/</code> directory.</li></div><a name="wp92966"> </a><div class="pSmartList1"><li>Type <code class="cCode">TransactedExample</code> in the File Name field and click Choose Module File.</li></div><a name="wp92967"> </a><div class="pSmartList1"><li>Verify that <code class="cCode">TransactedExample</code> appears in the AppClient Name field.</li></div><a name="wp92968"> </a><div class="pSmartList1"><li>Click the Edit button next to the Contents text area. </li></div><a name="wp92969"> </a><div class="pSmartList1"><li>In the dialog box, locate the <code class="cCode">build</code> directory. Select the six classes whose names begin with <code class="cCode">TransactedExample</code> from the Available Files tree and click Add.</li></div><a name="wp92970"> </a><div class="pSmartList1"><li>Select the two classes whose names begin with <code class="cCode">SampleUtilities</code> from the Available Files tree and click Add, then OK.</li></div><a name="wp96832"> </a><div class="pSmartList1"><li>Click Next.</li></div><a name="wp92971"> </a><div class="pSmartList1"><li>In the General screen, select <code class="cCode">TransactedExample</code> in the Main Class combo box.</li></div><a name="wp92972"> </a><div class="pSmartList1"><li>Click Next.</li></div><a name="wp92973"> </a><div class="pSmartList1"><li>Click Finish.</li></div></ol></div><a name="wp83830"> </a><p class="pBody">Run the program, specifying the number of computers to be ordered. To order three computers, use the following command:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">appclient -client TransactedExample.jar 3<a name="wp83838"> </a></pre></div><a name="wp83839"> </a><p class="pBody">The output looks something like this:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">Quantity to be ordered is 3Retailer: ordered 3 computer(s)Vendor: Retailer ordered 3 Computer(s)Vendor: ordered 3 monitor(s) and hard drive(s)Monitor Supplier: Vendor ordered 3 Monitor(s)Monitor Supplier: sent 3 Monitor(s)  Monitor Supplier: committed transaction  Vendor: committed transaction 1Hard Drive Supplier: Vendor ordered 3 Hard Drive(s)Hard Drive Supplier: sent 1 Hard Drive(s)Vendor: Completed processing for order 1  Hard Drive Supplier: committed transactionVendor: unable to send 3 computer(s)  Vendor: committed transaction 2Retailer: Order not filledRetailer: placing another orderRetailer: ordered 6 computer(s)Vendor: JMSException occurred: javax.jms.JMSException: Simulated database concurrent access exceptionjavax.jms.JMSException: Simulated database concurrent access exception        at TransactedExample$Vendor.run(Unknown Source)  Vendor: rolled back transaction 1Vendor: Retailer ordered 6 Computer(s)Vendor: ordered 6 monitor(s) and hard drive(s)Monitor Supplier: Vendor ordered 6 Monitor(s)Hard Drive Supplier: Vendor ordered 6 Hard Drive(s)Monitor Supplier: sent 6 Monitor(s)  Monitor Supplier: committed transactionHard Drive Supplier: sent 6 Hard Drive(s)  Hard Drive Supplier: committed transaction  Vendor: committed transaction 1Vendor: Completed processing for order 2Vendor: sent 6 computer(s)Retailer: Order filled  Vendor: committed transaction 2<a name="wp92991"> </a></pre></div><a name="wp88546"> </a><p class="pBody">When you have finished with this sample application, use the Admin Console to delete the physical destinations <code class="cCode">AQueueP</code>, <code class="cCode">BQueueP</code>, <code class="cCode">CQueueP</code>, and <code class="cCode">OTopicP</code>, and the destination resources <code class="cCode">AQueue</code>, <code class="cCode">BQueue</code>, <code class="cCode">CQueue</code>, and <code class="cCode">OTopic</code>.</p><a name="wp93115"> </a><p class="pBody">Use the following command to remove the class files:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">asant clean<a name="wp88552"> </a></pre></div><a name="wp93127"> </a><p class="pBody">If you wish, you can manually remove the client JAR files.</p><a name="wp97306"> </a><p class="pBody">The <code class="cCode">build.xml</code> file in the directory <code class="cCode">&lt;</code><code class="cVariable">INSTALL</code><code class="cCode">&gt;/j2eetutorial14/examples/jms/advanced</code> contains <code class="cCode">asant</code> targets for creating and deleting all the administered objects used in this chapter. If you want to run the examples again, you can recreate the objects quickly with the <code class="cCode">add-objects</code> target. Use the command <code class="cCode">asant</code> <code class="cCode">-projecthelp</code> to obtain a list of the targets.</p>    </blockquote>   <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider">    <table width="550" summary="layout" id="SummaryNotReq1">      <tr>	<td align="left" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a>	</td>        <td align="center" valign="center"><a accesskey="p" href="JMS5.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="JMS7.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a>        </td>	<td align="right" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font>	</font>	</td>      </tr>    </table>    <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"><p><font size="-1">All of the material in <em>The J2EE(TM) 1.4 Tutorial</em> is <a href="J2EETutorialFront2.html">copyright</a>-protected and may not be published in other workswithout express written permission from Sun Microsystems.</font>  </body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -