In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to write a group of ABAP procedures that will appear deadlocks". In daily operation, I believe many people have doubts about how to write a group of ABAP procedures that will appear deadlocks. Xiaobian consulted all kinds of information and sorted out simple and easy to use operation methods. I hope to answer everyone's doubts about "how to write a group of ABAP procedures that will appear deadlocks". Next, please follow the small series to learn together!
Let's start by looking at how to write a program in Java that will give rise to deadlocks.
Less than 40 lines of code to complete the task. For ABAP practitioners to understand, Lambda expressions in Java are not used, otherwise the code could be shorter.
The program logic is as follows:
Thread 1 holds resource 1 and attempts to hold resource 2; thread 2 holds resource 2 and attempts to hold resource 1; deadlock occurs;
Now move on to the ABAP section.
ABAP help document mentioned that when using SELECT SINGLE FOR UPDATE to read a single record, it will automatically set an Exclusive lock for the record at the database level (some Chinese documents are translated into exclusive locks). An exception is thrown if locking would cause a deadlock to occur.
So we first create an ABAP database table and insert two records:
Then develop two ABAP programs ZLOCK1 and ZLOCK2, respectively, according to the order Z01, Z02 and Z02, Z01 using SELECT SINGLE FOR UPDATE to initiate read requests to the database.
Open two SAP GUI windows and execute these two programs according to the following steps to generate deadlock.
(1)Step through program ZLOCK1 in debug mode and successfully execute SELECT SINGLE FOR UPDATE.. WHERE object_id ='Z 01'means that ZLOCK1 has a lock on record Z01 at the database level.
(2)Switch to another SAPGUI window, execute program ZLOCK2, step through statement SELECT SINGLE FOR UPDATE.. WHERE object_id = 'Z 02', i.e. ZLOCK2 successfully locks Z02 at the database level.
(3)Returning to Window 1, we continue debugging program ZLOCK1, where the debugger blocks because ZLOCK1 tries to lock Z02, and program ZLOCK2 holds the lock for Z02. Program ZLOCK1 is blocked, waiting for ZLOCK2 to release the lock set on record Z02.
(3)Go back to Window 2 and continue executing line 12 of ZLOCK2 in debug mode. At this point program ZLOCK2 tries to lock record Z01, but the record has been locked by program ZLOCK1, and program ZLOCK2 has to wait for program ZLOCK1 to release the lock on record Z01; program ZLOCK1 can never release the lock on record Z01 because it is already in the blocking state and waiting for program ZLOCK2 to release the lock on record Z02.
ABAP Kernel detects a deadlock in ZLOCK2 and throws a runtime exception, ending ZLOCK2's execution. The lock that program ZLOCK2 holds on record Z02 is also automatically released. The final result is that program ZLOCK1 successfully locks record Z02.
In transaction code ST22, we can observe the details of this deadlock.
ABAP Kernel This method of terminating programs immediately after detecting deadlocks saves application developers the time to analyze deadlocks by reading code.
Going back to the Java program before Jerry, the two threads get deadlocked after running, and nothing prints on the console for troubleshooting. However, JDK itself provides a convenient command-line tool for checking Java application deadlock status: jstack.
The command line executes jstack, passing in the process id of the Java program. If a deadlock occurs in the program, the tool will print out which line of code in the program and the deadlock occurred when trying to lock what resources, thus helping developers quickly locate the logically flawed code.
At this point, on "how to write a group of ABAP procedures will occur deadlock" learning is over, I hope to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.