Bugs in concurrent situations

Stimulsoft Reports.JAVA discussion
Post Reply
simon ren
Posts: 105
Joined: Wed Nov 21, 2018 12:51 am

Bugs in concurrent situations

Post 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");
}
}
Attachments
error.png
error.png (87.41 KiB) Viewed 11147 times
code.png
code.png (144.98 KiB) Viewed 11147 times
Vadim
Posts: 409
Joined: Tue Apr 23, 2013 11:23 am

Re: Bugs in concurrent situations

Post by Vadim »

Hello

Will be fixed in new version
Post Reply