If Snappy-Java supports Thread-Safe?
Recently I use Snappy-java for compressing bytes[] in Java. It's a multi-thread environment, I see your implementation is based on this code:
int compressedByteSize = ((SnappyNativeAPI) impl).rawCompress(data, 0, byteSize, buf, 0);
"impl" is a JNI implementation, I wonder that if it supports Thread-Safe or do you deal concurrent problem in JNI?
Thanks.
impl is a static field, and initialized in thread-safe manner. See also http://stackoverflow.com/questions/878577/are-java-static-initializers-thread-safe
Yes I see that it initialized thread-safely. What I wanna know is when I use Snappy.compress(byte[]) by about 1000 threads in the same time ,will it represent correctly? Since it's a static method and static field, I worry about it. Thanks.
2012/10/12 Taro L. Saito [email protected]
impl is a static field, and initialized thread-safe manner. See also
http://stackoverflow.com/questions/878577/are-java-static-initializers-thread-safe
— Reply to this email directly or view it on GitHubhttps://github.com/xerial/snappy-java/issues/16#issuecomment-9365245.
No shared state exists inside Snappy.compress code. You can used it safely from multiple threads.