Skip to content

Commit

Permalink
Load the first time you use hessian serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
funky-eyes committed Feb 2, 2024
1 parent 829be55 commit 3629a35
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package com.alipay.remoting.serialization;

import java.util.concurrent.locks.ReentrantLock;

/**
* Manage all serializers.
*
Expand All @@ -32,11 +34,19 @@ public class SerializerManager {
public static final byte Hessian2 = 1;
//public static final byte Json = 2;

static {
addSerializer(Hessian2, new HessianSerializer());
}

private static final ReentrantLock REENTRANT_LOCK = new ReentrantLock();

public static Serializer getSerializer(int idx) {
if (serializers[idx] == null && idx == Hessian2) {
REENTRANT_LOCK.lock();
try {
if (serializers[idx] == null) {
addSerializer(Hessian2, new HessianSerializer());
}
} finally {
REENTRANT_LOCK.unlock();
}
}
return serializers[idx];
}

Expand Down

0 comments on commit 3629a35

Please sign in to comment.