gpt4 book ai didi

concurrency - 我应该从 FindBugs 中得到什么并发警告?

转载 作者:行者123 更新时间:2023-12-04 02:51:07 24 4
gpt4 key购买 nike

我有以下代码:

import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.ThreadSafe;

@ThreadSafe
public class Aoeu {
@GuardedBy("this")
private long aoeu;

public long getAoeu() {
return aoeu;
}

public void setAoeu(long aoeu) {
this.aoeu = aoeu;
}
}

从我读到的内容来看,FindBugs 理解 JCiP 注释(实际上,1.3.9 随附了它们)但我没有从上面的代码中得到任何警告。根据,我希望看到:
IS: Field not guarded against concurrent access (IS_FIELD_NOT_GUARDED)

This field is annotated with net.jcip.annotations.GuardedBy, but can be accessed in a way that seems to violate the annotation.

最佳答案

请检查下面的代码它显示了错误

class Test 
{
@net.jcip.annotations.GuardedBy("this")
private int field;
/**
*
*/
public Test()
{

}

/**
*
*/
public void setField()
{
field++;
}

}

关于concurrency - 我应该从 FindBugs 中得到什么并发警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8479599/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com