Code: Select all
    
@Singleton
@LocalBean
@Lock(LockType.WRITE)
public class CrazySingletonBean {
    String s1 = "x";
    String s2 = "y";
    public void setStrings(){
        s1 = "x"; s2 = "y1";
    }
    public void clearStrings(){
        s1 = ""; s2 = "";
    }
 
    @Lock(LockType.READ)
    public String getValue(){
        return s1+" "+s2;
    }
}
1. Thread_A executes getVaule(), but it is suspended right after concatening s1 and " " ("x" + " ")
2. then Thread_B executes clearStrings() - method completes (because it have LockType.WRITE)
3. Thread_A reasume and continue with concatenation s2 but now it has "" and when conacatenation completes it result is "x "
Both types of method (writing and reading variables) should have lock type = WRITE.