Top 29 Java Transaction Management Interview Questions You Must Prepare 02.Oct.2022

The resource manager is nothing but a relational database management system (RDBMS), such as Oracle, SQL Server. The actual database management is handled by this component.

  • When an enterprise bean defines the boundaries of the traction it is referred as bean-managed traction. In bean-managed traction demarcation, the code in the session or message-driven bean explicitly marks the boundaries of the traction.
  • Although be with container-managed tractions require less coding, they have one limitation: When a method is executing, it can be associated with either a single traction or no traction at all. If we use bean managed traction we are responsible for programming traction logic into your application code so that developers are responsible for issuing a 'begin' statement and either a 'commit' or an 'abort' statement.
  • The benefit of bean managed traction is that as a developer you have full control over tractional boundaries. For instance, you can run series of mini tractions within a bean's method using bean managed traction.

Required New is used when the required results of the tractions to be committed irrespective of the caller's tractions.

If a client has an associated traction and calls a container-managed bean's method then the method executes within the client traction.

If the client is not associated with a traction then the container starts a new traction before calling the bean's method.

  • Required,
  • Requires New,
  • Mandatory,
  • Not Supported,
  • Supports,
  • Never.

If a client has an associated traction and calls a container-managed bean's method then the container suspends the client’s traction, starts a new traction, starts the call to the method and starts the client’s traction after method completes.

If the client is not associated with a traction then the container starts a new traction before calling the be method.

Traction demarcation always wraps a sequence of actions, such as a single request, a single method, or a section of code within a method. The demarcation initializes some tractional behavior before the demarcated area begins, then ends that tractional behavior when the demarcated area ends. The application server uses these demarcations to determine the appropriate calls to the Traction Manager object.

Declarative Demarcation: When using declarative demarcation, you specify what traction demarcation modes should be used around certain areas of code. Rather than implementing these demarcations directly in your code, you declare the demarcations in a configuration file or deployment descriptor. The application server is then responsible for making sure that the correct tractional behavior is used around the specified area.

Programmatic Demarcation: At times, you might need to demarcate tractions in your code. Generally, you should use programmatic demarcation as little as possible, as it is error-prone and can interfere with the application servers own traction demarcation mechanisms. If you find it necessary to use programmatic demarcation, you must be very careful to ensure that your code handles any unexpected errors and conditions.

Tractions in Java EE application are a series of actions that all must be completed successfully, or else the changes in each action are backed out. If all the actions are successful then the changes from all actions are committed. If any one of the actions is unsuccessful then the changes from all the actions are rolled back.

Tractions in EJB application are either Container-Managed or Bean-Managed.

Container-Managed Tractions - In Container-Managed tractions the traction boundaries are set in the EJB container. Container-managed tractions can be set for both session be as well as message-driven be.

Bean-Managed Tractions - In Bean-Managed tractions the traction boundaries are set specifically within the bean's code. Bean managed tractions can be set for session be as well as message-driven be. Bean manages traction can either use JDBC tractions or JTA tractions.

  • Java Traction API (JTA) specifies standard Java interfaces between a traction manager and the parties involved in a distributed traction system: the resource manager, the application server, and the tractional applications.
  • The JTA allows applications to perform distributed tractions, that is, tractions that access and update data on two or more networked computer resources.
  • The Java Traction API consists of three elements: a high-level application traction demarcation interface, a high-level traction manager interface intended for an application server, and a standard Java mapping of the X/Open XA protocol intended for a tractional resource manager.

Java Traction API is an API specified in Java EE that provides applications a standard way to access tractions independent of any specific implementation. JTA tractions are controlled by Java EE traction manager. Traction are started, committed or rolled back by calling corresponding methods on the User Traction API.

If a client has an associated traction and calls a container-managed bean's method then the container suspends the client’s traction, calls the bean's method, and starts the client’s traction after method execution completes.

If a client is not associated with a traction, then the container does not start a new traction before calling the bean's method.

The javax.traction.Tractional annotation provides the application the ability to control traction boundaries declaratively. This annotation can be applied to any class that the Java EE specification defines as a managed bean (which includes CDI managed be).

  • The application,
  • Application server,
  • Traction manager,
  • Resource adapter,
  • and the resource manager.

No, the J2EE platform supports only flat tractions.

Traction attribute determines the scope of a traction across be. For example, if method () of Bean A starts a traction and calls method () of bean b, then does method () run within the traction started by method (). This is determined by the traction attribute set on method ()

A traction attribute can have one of the following values:-

  1. Required
  2. Requires New
  3. Mandatory
  4. Not Supported
  5. Supports
  6. Never

Use the Mandatory attribute if the enterprise be method must use the traction of the client.

If the client is running within a traction and invokes the enterprise be method, the method executes within the clients traction. If the client is not associated with a traction, the container throws the Traction Required Exception.

JTS is a specification for implementing a Java traction manager. A traction manager serves as an intermediary between an application and one or more traction-capable resource managers such as database servers and messaging systems. The JTA specification encompasses the JTA API specification.

No. Entity be always use container-managed traction demarcation. Session be can use either container-managed or bean-managed traction demarcation, but not at the same time.

If a client has an associated traction and calls a container-managed bean method then the method executes within the client traction.

If a client is not associated with a traction, then the container does not start a new traction before calling the bean's method.

No. Simply putting a tractional attribute on a method won't help if the resource manager can't use a tractional context.

If a client has an associated traction and calls a container-managed bean's method then the method executes within the client traction.

If a client is not associated with a traction then the container throws a TractionRequiredException.

In the X/Open XA architecture, a traction manager or traction processing monitor (TP monitor) coordinates the tractions across multiple resources such as databases and message queues. Each resource has its own resource manager. The resource manager typically has its own API for manipulating the resource, for example the JDBC API to work with relational databases. In addition, the resource manager allows a TP monitor to coordinate a distributed traction between its own and other resource managers. Finally, there is the application which communicates with the TP monitor to begin, commit or rollback the tractions. The application also communicates with the individual resources using their own API to modify the resource.

The resource adapter is the component that acts as a communications channel, or request trlator, between the "outside world,” the application, and the resource manager. A JDBC driver is an example of resource adapter.

Required is the default traction attribute that ensures the methods are invoked within Java Traction API traction context. Required makes the tractional context used by the bean. If not the new context will be created.

A traction defines a logical unit of work that either completely succeeds or produces no result at all.

A distributed traction is simply a traction that accessed and updated data on two or more networked resources, and therefore must be coordinated among those resources.

If a client has an associated traction and calls a container-managed bean's method then the container throws a Remote Exception.

If a client is not associated with a traction, then the container does not start a new traction before calling the bean's method.

Container-Managed Traction - In container managed tractions the traction timeout is set at the container's administration console.

Bean-Managed Tractions - In Bean-managed tractions, the traction timeout is set by calling the setTractionTimeout () method of the User Traction interface.