session.html

来自「SUN公司官方J2EE中文帮助文档 应该不错 有兴趣的下来看看 html格式的」· HTML 代码 · 共 793 行 · 第 1/3 页

HTML
793
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc on Thu Jan 17 03:51:32 PST 2002 -->
<TITLE>
Java 2 Platform EE v1.3: Interface  Session
</TITLE>
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
</HEAD>
<BODY BGCOLOR="white">

<!-- ========== START OF NAVBAR ========== -->
<A NAME="navbar_top"><!-- --></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
  <TR ALIGN="center" VALIGN="top">
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
  </TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>

<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../javax/jms/ServerSessionPool.html"><B>PREV CLASS</B></A>&nbsp;
&nbsp;<A HREF="../../javax/jms/StreamMessage.html"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
  <A HREF="../../index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
&nbsp;<A HREF="Session.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
  SUMMARY: &nbsp;INNER&nbsp;|&nbsp;<A HREF="#field_summary">FIELD</A>&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL: &nbsp;<A HREF="#field_detail">FIELD</A>&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<!-- =========== END OF NAVBAR =========== -->

<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">
javax.jms</FONT>
<BR>
Interface  Session</H2>
<DL>
<DT><B>All Superinterfaces:</B> <DD>java.lang.Runnable</DD>
</DL>
<DL>
<DT><B>All Known Subinterfaces:</B> <DD><A HREF="../../javax/jms/QueueSession.html">QueueSession</A>, <A HREF="../../javax/jms/TopicSession.html">TopicSession</A>, <A HREF="../../javax/jms/XAQueueSession.html">XAQueueSession</A>, <A HREF="../../javax/jms/XASession.html">XASession</A>, <A HREF="../../javax/jms/XATopicSession.html">XATopicSession</A></DD>
</DL>
<HR>
<DL>
<DT>public interface <B>Session</B><DT>extends java.lang.Runnable</DL>

<P>
<P>A <CODE>Session</CODE> object is a single-threaded context for producing and consuming 
 messages. Although it may allocate provider resources outside the Java 
 virtual machine (JVM), it is considered a lightweight JMS object.

 <P>A session serves several purposes:

 <UL>
   <LI>It is a factory for its message producers and consumers.
   <LI>It supplies provider-optimized message factories.
   <LI>It supports a single series of transactions that combine work 
       spanning its producers and consumers into atomic units.
   <LI>It defines a serial order for the messages it consumes and 
       the messages it produces.
   <LI>It retains messages it consumes until they have been 
       acknowledged.
   <LI>It serializes execution of message listeners registered with 
       its message consumers.
 </UL>

 <P>A session can create and service multiple message producers and 
 consumers.

 <P>One typical use is to have a thread block on a synchronous 
 <CODE>MessageConsumer</CODE> until a message arrives. The thread may then
 use one or more of the <CODE>Session</CODE>'s <CODE>MessageProducer</CODE>s.

 <P>If a client desires to have one thread produce messages while others 
 consume them, the client should use a separate session for its producing 
 thread.

 <P>Once a connection has been started, any session with one or more 
 registered message listeners is dedicated to the thread of control that 
 delivers messages to it. It is erroneous for client code to use this session
 or any of its constituent objects from another thread of control. The
 only exception to this rule is the use of the session or connection 
 <CODE>close</CODE> method.

 <P>It should be easy for most clients to partition their work naturally
 into sessions. This model allows clients to start simply and incrementally
 add message processing complexity as their need for concurrency grows.

 <P>The <CODE>close</CODE> method is the only session method that can be 
 called while some other session method is being executed in another thread.

 <P>A session may be specified as transacted. Each transacted 
 session supports a single series of transactions. Each transaction groups 
 a set of message sends and a set of message receives into an atomic unit 
 of work. In effect, transactions organize a session's input message 
 stream and output message stream into series of atomic units. When a 
 transaction commits, its atomic unit of input is acknowledged and its 
 associated atomic unit of output is sent. If a transaction rollback is 
 done, the transaction's sent messages are destroyed and the session's input 
 is automatically recovered.

 <P>The content of a transaction's input and output units is simply those 
 messages that have been produced and consumed within the session's current 
 transaction.

 <P>A transaction is completed using either its session's <CODE>commit</CODE>
 method or its session's <CODE>rollback</CODE> method. The completion of a
 session's current transaction automatically begins the next. The result is
 that a transacted session always has a current transaction within which its 
 work is done.  

 <P>The Java Transaction Service (JTS) or some other transaction monitor may 
 be used to combine a session's transaction with transactions on other 
 resources (databases, other JMS sessions, etc.). Since Java distributed 
 transactions are controlled via the Java Transaction API (JTA), use of the 
 session's <CODE>commit</CODE> and <CODE>rollback</CODE> methods in 
 this context is prohibited.

 <P>The JMS API does not require support for JTA; however, it does define 
 how a provider supplies this support.

 <P>Although it is also possible for a JMS client to handle distributed 
 transactions directly, it is unlikely that many JMS clients will do this.
 Support for JTA in the JMS API is targeted at systems vendors who will be 
 integrating the JMS API into their application server products.
<P>
<DL>
<DT><B>See Also: </B><DD><A HREF="../../javax/jms/QueueSession.html"><CODE>QueueSession</CODE></A>, 
<A HREF="../../javax/jms/TopicSession.html"><CODE>TopicSession</CODE></A>, 
<A HREF="../../javax/jms/XASession.html"><CODE>XASession</CODE></A></DL>
<HR>

<P>
<!-- ======== INNER CLASS SUMMARY ======== -->


<!-- =========== FIELD SUMMARY =========== -->

<A NAME="field_summary"><!-- --></A>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=2><FONT SIZE="+2">
<B>Field Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/jms/Session.html#AUTO_ACKNOWLEDGE">AUTO_ACKNOWLEDGE</A></B></CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;With this acknowledgment mode, the session automatically acknowledges
 a client's receipt of a message either when the session has successfully 
 returned from a call to <CODE>receive</CODE> or when the message 
 listener the session has called to process the message successfully 
 returns.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/jms/Session.html#CLIENT_ACKNOWLEDGE">CLIENT_ACKNOWLEDGE</A></B></CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;With this acknowledgment mode, the client acknowledges a consumed 
 message by calling the message's <CODE>acknowledge</CODE> method.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/jms/Session.html#DUPS_OK_ACKNOWLEDGE">DUPS_OK_ACKNOWLEDGE</A></B></CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This acknowledgment mode instructs the session to lazily acknowledge 
 the delivery of messages.</TD>
</TR>
</TABLE>
&nbsp;
<!-- ======== CONSTRUCTOR SUMMARY ======== -->


<!-- ========== METHOD SUMMARY =========== -->

<A NAME="method_summary"><!-- --></A>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=2><FONT SIZE="+2">
<B>Method Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/jms/Session.html#close()">close</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Closes the session.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/jms/Session.html#commit()">commit</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Commits all messages done in this transaction and releases any locks
 currently held.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../../javax/jms/BytesMessage.html">BytesMessage</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/jms/Session.html#createBytesMessage()">createBytesMessage</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Creates a <CODE>BytesMessage</CODE> object.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../../javax/jms/MapMessage.html">MapMessage</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/jms/Session.html#createMapMessage()">createMapMessage</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Creates a <CODE>MapMessage</CODE> object.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../../javax/jms/Message.html">Message</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/jms/Session.html#createMessage()">createMessage</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Creates a <CODE>Message</CODE> object.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../../javax/jms/ObjectMessage.html">ObjectMessage</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/jms/Session.html#createObjectMessage()">createObjectMessage</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Creates an <CODE>ObjectMessage</CODE> object.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../../javax/jms/ObjectMessage.html">ObjectMessage</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/jms/Session.html#createObjectMessage(java.io.Serializable)">createObjectMessage</A></B>(java.io.Serializable&nbsp;object)</CODE>

<BR>

⌨️ 快捷键说明

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