![Red Hat Application Server Скачать руководство пользователя страница 145](http://html.mh-extra.com/html/red-hat/application-server/application-server_manual_1427406145.webp)
Chapter 11. Transactional Behavior of EJB Applications
137
11.2. Bean-managed Transactions
A bean that manages its transactions itself must set the
transaction-type
element in its standard
deployment descriptor to:
transaction-type
Bean
/transaction-type
To demarcate the transaction boundaries in a bean with bean-managed transactions, the bean program-
mer should use the
javax.transaction.UserTransaction
interface, which is defined on an EJB
server object that may be obtained using the
EJBContext.getUserTransaction()
method (the
SessionContext object or the EntityContext object depending on whether the method is defined on a
session or on an Entity Bean).
The following example shows a Session Bean method
doTxJob
demarcating the transaction bound-
aries; the UserTransaction object is obtained from the sessionContext object, which should have been
initialized in the setSessionContext method (refer to the Section 7.4
The Enterprise Bean Class
).
public void doTxJob() throws
RemoteException {
UserTransaction ut = sessionContext.getUserTransaction();
ut.begin();
... // transactional operations
ut.commit();
}
Another way to do this is to use JNDI and to retrieve UserTransaction with the name
java:comp/UserTransaction
in the initial context.
11.3. Distributed Transaction Management
As explained in the previous section, the transactional behavior of an application can be defined in a
declarative way or coded in the bean and/or the client itself (transaction boundaries demarcation). In
any case, the distribution aspects of the transactions are completely transparent to the bean provider
and to the application assembler. This means that a transaction may involve beans located on several
JOnAS servers and that the platform itself will handle management of the global transaction. It will
perform the two-phase commit protocol between the different servers, and the bean programmer need
do nothing.
Once the beans have been developed and the application has been assembled, it is possible for the
deployer and for the administrator to configure the distribution of the different beans on one or several
machines, and within one or several JOnAS servers. This can be done without impacting either the
beans’ code or their deployment descriptors. The distributed configuration is specified at launch time.
In the environment properties of an EJB server, the following can be specified:
•
Which Enterprise Beans the JOnAS server will handle
•
If a Java Transaction Monitor will be located in the same Java Virtual Machine (JVM) or not.
To achieve this goal, two properties must be set in the
jonas.properties
file,
jonas.service.ejb.descriptors
and
jonas.service.jtm.remote
. The first one lists the
beans that will be handled on this server (by specifying the name of their EJB-JAR files), and the
second one sets the Java Transaction Monitor (JTM) launching mode:
•
If set to
true
, the JTM is remote, that is, the JTM must be launched previously in another JVM
•
If set to
false
, the JTM is local, that is, it will run in the same JVM as the EJB Server.
Example:
jonas.service.ejb.descriptors
Bean1.jar, Bean2.jar
Содержание Application Server
Страница 1: ...Red Hat Application Server JOnAS User Guide ...
Страница 8: ......
Страница 22: ...14 Chapter 1 Java Open Application Server JOnAS a J2EE Platform ...
Страница 58: ...50 Chapter 3 JOnAS Configuration ...
Страница 66: ...58 Chapter 5 JOnAS Class Loader Hierarchy ...
Страница 78: ...70 Chapter 6 JOnAS Command Reference ...
Страница 80: ......
Страница 86: ...78 Chapter 7 Developing Session Beans ...
Страница 136: ...128 Chapter 9 Developing Message Driven Beans ...
Страница 142: ...134 Chapter 10 Defining the Deployment Descriptor ...
Страница 148: ...140 Chapter 11 Transactional Behavior of EJB Applications ...
Страница 158: ...150 Chapter 14 EJB Packaging ...
Страница 162: ...154 Chapter 15 Application Deployment and Installation Guide ...
Страница 164: ......
Страница 176: ...168 Chapter 18 WAR Packaging ...
Страница 178: ......
Страница 184: ...176 Chapter 20 Defining the Client Deployment Descriptor ...
Страница 186: ...178 Chapter 21 Client Packaging ...
Страница 188: ......
Страница 192: ...184 Chapter 23 EAR Packaging ...
Страница 194: ......
Страница 200: ...192 Chapter 24 JOnAS Services ...
Страница 204: ...196 Chapter 25 JOnAS and the Connector Architecture ...
Страница 222: ...214 Chapter 27 Ant EJB Tasks Using EJB JAR ...
Страница 234: ...226 Chapter 29 Web Services with JOnAS ...
Страница 236: ......
Страница 260: ...252 Chapter 34 How to use Axis in JOnAS ...
Страница 270: ...262 Chapter 36 Web Service Interoperability between JOnAS and BEA WebLogic ...
Страница 296: ......