支持jdk17
This commit is contained in:
@@ -26,6 +26,12 @@ import org.springframework.core.NamedThreadLocal;
|
|||||||
public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
|
public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(ObjectUtils.class);
|
private static Logger logger = LoggerFactory.getLogger(ObjectUtils.class);
|
||||||
|
private static final boolean isJavaSerialize;
|
||||||
|
|
||||||
|
static {
|
||||||
|
String[] ver = StringUtils.split(System.getProperty("java.version"), '.');
|
||||||
|
isJavaSerialize = ver.length > 0 && Integer.parseInt(ver[0]) > 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换为 Double 类型
|
* 转换为 Double 类型
|
||||||
@@ -155,8 +161,12 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static byte[] serialize(Object object) {
|
public static byte[] serialize(Object object) {
|
||||||
|
if (isJavaSerialize) {
|
||||||
|
return ObjectUtils.serializeJava(object);
|
||||||
|
}else {
|
||||||
return ObjectUtils.serializeFst(object);
|
return ObjectUtils.serializeFst(object);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 反序列化对象
|
* 反序列化对象
|
||||||
@@ -164,8 +174,12 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Object unserialize(byte[] bytes) {
|
public static Object unserialize(byte[] bytes) {
|
||||||
|
if (isJavaSerialize) {
|
||||||
|
return ObjectUtils.unserializeJava(bytes);
|
||||||
|
}else {
|
||||||
return ObjectUtils.unserializeFst(bytes);
|
return ObjectUtils.unserializeFst(bytes);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 序列化对象
|
* 序列化对象
|
||||||
@@ -212,7 +226,7 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
long totalTime = System.currentTimeMillis() - beginTime;
|
long totalTime = System.currentTimeMillis() - beginTime;
|
||||||
if (totalTime > 3000){
|
if (totalTime > 3000 && object != null){
|
||||||
logger.warn(object.getClass() + " unserialize time: " + TimeUtils.formatDateAgo(totalTime));
|
logger.warn(object.getClass() + " unserialize time: " + TimeUtils.formatDateAgo(totalTime));
|
||||||
}
|
}
|
||||||
return object;
|
return object;
|
||||||
@@ -255,7 +269,7 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
|
|||||||
long beginTime = System.currentTimeMillis();
|
long beginTime = System.currentTimeMillis();
|
||||||
Object object = fstConfiguration.get().asObject(bytes);
|
Object object = fstConfiguration.get().asObject(bytes);
|
||||||
long totalTime = System.currentTimeMillis() - beginTime;
|
long totalTime = System.currentTimeMillis() - beginTime;
|
||||||
if (totalTime > 3000){
|
if (totalTime > 3000 && object != null){
|
||||||
logger.warn(object.getClass() + " fst unserialize time: " + TimeUtils.formatDateAgo(totalTime));
|
logger.warn(object.getClass() + " fst unserialize time: " + TimeUtils.formatDateAgo(totalTime));
|
||||||
}
|
}
|
||||||
return object;
|
return object;
|
||||||
|
|||||||
Reference in New Issue
Block a user