xuzifu666 commented on code in PR #9788:
URL: https://github.com/apache/hudi/pull/9788#discussion_r1338609304
##########
hudi-common/src/main/java/org/apache/hudi/common/util/ReflectionUtils.java:
##########
@@ -48,19 +48,17 @@ public class ReflectionUtils {
private static final Map<String, Class<?>> CLAZZ_CACHE = new HashMap<>();
public static Class<?> getClass(String clazzName) {
- if (!CLAZZ_CACHE.containsKey(clazzName)) {
- synchronized (CLAZZ_CACHE) {
- if (!CLAZZ_CACHE.containsKey(clazzName)) {
- try {
- Class<?> clazz = Class.forName(clazzName);
- CLAZZ_CACHE.put(clazzName, clazz);
- } catch (ClassNotFoundException e) {
- throw new HoodieException("Unable to load class", e);
- }
+ synchronized (CLAZZ_CACHE) {
Review Comment:
> This creates a bottleneck in the code since you need to take a lock every
time you call into this method. This will block your threads even when the
cache contains the class. Why is this better?
sychnozied block in jdk8 had improve use biasedlock,this is not lock less
and cost little,more important like this can avoid npe and other thread safe
problem. @the-other-tim-brown
##########
hudi-common/src/main/java/org/apache/hudi/common/util/ReflectionUtils.java:
##########
@@ -48,19 +48,17 @@ public class ReflectionUtils {
private static final Map<String, Class<?>> CLAZZ_CACHE = new HashMap<>();
public static Class<?> getClass(String clazzName) {
- if (!CLAZZ_CACHE.containsKey(clazzName)) {
- synchronized (CLAZZ_CACHE) {
- if (!CLAZZ_CACHE.containsKey(clazzName)) {
- try {
- Class<?> clazz = Class.forName(clazzName);
- CLAZZ_CACHE.put(clazzName, clazz);
- } catch (ClassNotFoundException e) {
- throw new HoodieException("Unable to load class", e);
- }
+ synchronized (CLAZZ_CACHE) {
Review Comment:
> This creates a bottleneck in the code since you need to take a lock every
time you call into this method. This will block your threads even when the
cache contains the class. Why is this better?
sychnozied block in jdk8 had improve use biasedlock,this is not lock less
and cost little,more important like this can avoid npe and other thread safe
problem. @the-other-tim-brown
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]