Add locking to comparator jni callback methods which must be thread-safe