Page 1 of 1

Bugs in concurrent situations

Posted: Thu Feb 20, 2025 3:32 am
by simon ren
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");
}
}

Re: Bugs in concurrent situations

Posted: Thu Feb 20, 2025 11:25 am
by Vadim
Hello

Will be fixed in new version