Do @Setter and @Getter lombok annotations can be thread safe?

I have a problem with my SessionCanal class, when I use the "idSession" attribute in a web service, it changes on multiple requests, I want to know if Setters and Getters can be thread safe (they are synchronized in some way)

@NoArgsConstructor
public class SesionCanal implements Serializable{
    private static final long serialVersionUID = 360569424947712753L;

    @Getter @Setter private String idSesion;
}

      

Thank you for your help.

+3


source to share


1 answer


Short answer: No.

Servlets are not thread safe by default, and getter / setter methods (automatically generated by annotations or manually) are not thread safe. if you need read / write access and you also need thread safety, you need to synchronize access.



Have a look at Handling Threading Issues in the Oracle documentation.

I personally prefer to use getter and setter methods for manual code. In particular, for such situations.

+2


source







All Articles