反序列化遇到异常时忽略
This commit is contained in:
@@ -161,11 +161,16 @@ 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) {
|
try {
|
||||||
return ObjectUtils.serializeJava(object);
|
if (isJavaSerialize) {
|
||||||
}else {
|
return ObjectUtils.serializeJava(object);
|
||||||
return ObjectUtils.serializeFst(object);
|
}else {
|
||||||
|
return ObjectUtils.serializeFst(object);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("serialize", e);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -174,11 +179,16 @@ 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) {
|
try {
|
||||||
return ObjectUtils.unserializeJava(bytes);
|
if (isJavaSerialize) {
|
||||||
}else {
|
return ObjectUtils.unserializeJava(bytes);
|
||||||
return ObjectUtils.unserializeFst(bytes);
|
}else {
|
||||||
|
return ObjectUtils.unserializeFst(bytes);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("unserialize", e);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -200,7 +210,7 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
long totalTime = System.currentTimeMillis() - beginTime;
|
long totalTime = System.currentTimeMillis() - beginTime;
|
||||||
if (totalTime > 3000){
|
if (totalTime > 30000){
|
||||||
logger.warn(object.getClass() + " serialize time: " + TimeUtils.formatDateAgo(totalTime));
|
logger.warn(object.getClass() + " serialize time: " + TimeUtils.formatDateAgo(totalTime));
|
||||||
}
|
}
|
||||||
return bytes;
|
return bytes;
|
||||||
@@ -226,7 +236,7 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
long totalTime = System.currentTimeMillis() - beginTime;
|
long totalTime = System.currentTimeMillis() - beginTime;
|
||||||
if (totalTime > 3000 && object != null){
|
if (totalTime > 30000 && object != null){
|
||||||
logger.warn(object.getClass() + " unserialize time: " + TimeUtils.formatDateAgo(totalTime));
|
logger.warn(object.getClass() + " unserialize time: " + TimeUtils.formatDateAgo(totalTime));
|
||||||
}
|
}
|
||||||
return object;
|
return object;
|
||||||
@@ -251,7 +261,7 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
|
|||||||
long beginTime = System.currentTimeMillis();
|
long beginTime = System.currentTimeMillis();
|
||||||
byte[] bytes = fstConfiguration.get().asByteArray(object);
|
byte[] bytes = fstConfiguration.get().asByteArray(object);
|
||||||
long totalTime = System.currentTimeMillis() - beginTime;
|
long totalTime = System.currentTimeMillis() - beginTime;
|
||||||
if (totalTime > 3000){
|
if (totalTime > 30000){
|
||||||
logger.warn(object.getClass() + " fst serialize time: " + TimeUtils.formatDateAgo(totalTime));
|
logger.warn(object.getClass() + " fst serialize time: " + TimeUtils.formatDateAgo(totalTime));
|
||||||
}
|
}
|
||||||
return bytes;
|
return bytes;
|
||||||
@@ -269,7 +279,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 && object != null){
|
if (totalTime > 30000 && 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