The course is part of this learning path
In this course, we will learn the concepts of Java EE 7 with a focus on Concurrency Utilities with Threads, Semaphore, Phaser and other methods, and Transactions.
- Concurrency Utilities
- Anyone looking to get Oracle Java Certification
- Those who want to improve Java 7 EE knowledge
- Java developers
- Have at least 2 years of Java development experience
Hello there. In this lesson, we will talk about transactions. So, let's start. Transactions are extremely critical for developing reliable enterprise applications. The most common type of transaction concept is data-based transactions. In a typical database update process, the database transaction starts, the data is updated and the transaction is committed or rolled back. Transaction literally means transaction. However, the concept of transaction will not be enough to explain the concept of transaction we mentioned. In order to better understand the concept of transaction, when we go to the cinema, these steps will take place until we buy a ticket. We choose the place where we will sit and we approve this place. This place is reserved for us, the seat we sit on is locked, someone else cannot choose this place as of now. We make the payment, we get our ticket. As in this example, we can start our movie enjoyment after all four steps are successful. If there is any problem in any of these steps, all steps will be invalid and the transaction will be completely canceled. For example, as a result of not having money to buy tickets, we cannot make the payment and the transaction will be canceled.
The seat reserved for us will become active again. We give the name transaction to all of the transactions that we have expressed in four steps here. If all steps are successful for a transaction, the transaction is committed. Otherwise, if there is a problem in any step in a transaction, the transaction rollback is performed. When the transaction rollback is done, the successful steps before it does not matter. Everything done in these steps is taken back. The all or nothing rule works for the transaction. These steps are called ACID. The concept of ACID; atomicity, consistency, isolation, durability, is a set of features that guarantees reliable operation of database transactions. The concept of ACID was defined in 1983 by Andreas Ruder and Theo Harder. Atomicity; transaction consists of one or more job, operation, activity, work piece. In our movie ticket example, we expressed the particles with four items. Atomic rule; However, it means that the transaction is successful when all the threads are successful or that the entire transaction is unsuccessful as a result of the failure of one thread. As a result of a step thread failure, the threads made in the previous steps are canceled and restored as if they had never happened.
Roll back- atomicity feature; It's an all or nothing rule. All or nothing. Consistent; let's consider a database system as an example. An example of the consistent feature is to ensure consistency in the database when the transaction that affects the database is executed: add, update, delete etc. As another example, let's consider an EFT or money order transaction. After the EFT or money transfer transaction, the fee you send from your account and the fee deposited into the account on the other side must be consistent. There can be more than one operation on the same data. For this reason, reading or writing on the same data at the same time should be prevented. Considering our example, after choosing and confirming our place while our transaction is in progress, we haven't paid the ticket yet. Someone else shouldn't be able to come and choose the place we choose. Work pieces within the transaction should not be affected by other transactions and should work in isolation. This isolation structure is provided by the locking structure in databases such as row or table locking. Durability. Durable means durable, solid, permanent. When a transaction terminates, the results of that transaction must become permanent.
As a result of a thread failure, the thread made in the previous steps are canceled and should be able to be restored as if they had never happened. Transaction type. Transaction is divided into two as local transaction and global transaction. Local transactions refer to a single transactional resource, for example, JDBC. Global transactions can span multiple transactional resources. Global transactions are managed by containers. Local transactions are easier to manage. If our application will interact with a single transactional resource, then local transition will be sufficient. In the world of Java, global transactions are made with JTA, Java Transaction API implementation. When we examine the figure, we can see more than one resource in the global transaction, RDBMS, Message Middleware and Enterprise Resource Planning, ERP system. Resource managers are responsible for the management of resources.
For example, MySQL XA data source class for MySQL is responsible for the resource manager task. Resource managers communicate with XA protocol and two-phase commit, 2PC mechanism is used. Thus, all backend data sources are up to date. JTA transaction manager is responsible for the management and coordination of transactions supported by java EE compatible application servers such as JTA, J boss, WebSphere, WebLogic, Glassfish or Apache tom EE. JTA is not supported in software, the only feature servlet container such as Apache tomcat. So, that's it. Hope to see you in our next lesson. Have a nice day.
OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.