Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If I don't synchronize this method I'll get wrong values?

public static int getCRC16(byte[] bytes) {
    CRC16 crc = new CRC16();
    crc.reset();
    crc.update(bytes, 0, bytes.length);
    return (int) crc.getValue();
}

Tons of threads will hit this method, if I don't synchronize I'll get a wrong crc for a specific thread?

like image 825
tiagomac Avatar asked Dec 29 '25 10:12

tiagomac


1 Answers

No, it is fine, as long as you don't use any shared variables. The bytesand crcare local per thread. That's why they are called local variables.

like image 174
Niels Bech Nielsen Avatar answered Dec 30 '25 22:12

Niels Bech Nielsen