Get the App
SLTechnology News&Howtos  ›  Development  › 

Example analysis of atomicity of striving fault in java

Shulou Source: shulou.com Published: 2022-06-01 06:16:57 10月04日 Update

This article shares with you the content of the example analysis in java that strives for atomicity of faults. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Strive for fault atomicity

Item 8 is about failure. The general rule is that failed methods should not change the state of objects in the method. In order to fail as soon as possible, one way is to check the validity of the parameters before performing the operation. The following is a good example of following this tip.

/ * Assigns a new int value to location index of the buffer instance. * @ param index int * @ param newValue int * / public void modifyEntry (int index, int newValue) {if (index)

< 0 || index >

Size-1) {throw new IndexOutOfBoundsException ();} / ((int []) bufferArrayList.get ((int) (index / pageSize) [index% pageSize] = ((int []) bufferArrayList.get ((index > > exp) [index & r] = newValue;} Thank you for reading! This is the end of the article on "sample Analysis of failure atomicity in java". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Atom fault example method analysis content more article good practical effective parameter object article is in validity state see knowledge rules Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Apple Shulou Information Linux Xiaomi