Hello,
Recently, a bug occurred in the concurrent situation as shown in the diagram, which was ultimately located in your code.
It is caused by the static variable in the figure. When the first thread calls, this variable is empty, so the add method is executed.
However, if the second thread calls at this time and the first thread has not yet completed adding, but this variable is no longer empty, the second thread continues to execute, resulting in an error.
The correct code here should not use static methods, but rather static code blocks, such as
static {
if(goodApiList.isEmpty()){
goodApiList.add("A");
goodApiList.add("B");
goodApiList.add("c");
goodApiList.add("D");
goodApiList.add("E");
goodApiList.add("F");
goodApiList.add("G"),
goodApiList.add("H");
goodApiList.add("I");
goodApiList.add("j");
goodApiList.add("K");
}
}
Bugs in concurrent situations
Bugs in concurrent situations
- Attachments
-
- error.png (87.41 KiB) Viewed 11145 times
-
- code.png (144.98 KiB) Viewed 11145 times
Re: Bugs in concurrent situations
Hello
Will be fixed in new version
Will be fixed in new version