diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index 0363cea5..6dcbb7e0 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -1268,9 +1268,10 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 - 29、GLUE脚本文件自动清理功能,及时清理过期脚本文件; - 30、执行器注册方式切换优化,切换自动注册时主动同步在线机器,避免执行器为空的问题; - 31、跨平台:除了提供Java、Python、PHP等十来种任务模式之外,新增提供基于HTTP的任务模式; -- 32、【迭代中】分片任务失败重试优化,仅重试当前失败的分片; -- 33、【迭代中】支持通过API服务操作任务信息; -- 34、【迭代中】底层RPC协议更换为hessian2; +- 32、底层RPC序列化协议调整为hessian2; +- 33、【迭代中】分片任务失败重试优化,仅重试当前失败的分片; +- 34、【迭代中】支持通过API服务操作任务信息; + ### TODO LIST diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/rpc/serialize/HessianSerializer.java b/xxl-job-core/src/main/java/com/xxl/job/core/rpc/serialize/HessianSerializer.java index eda07ff4..1bb59ec4 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/rpc/serialize/HessianSerializer.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/rpc/serialize/HessianSerializer.java @@ -1,7 +1,7 @@ package com.xxl.job.core.rpc.serialize; -import com.caucho.hessian.io.HessianInput; -import com.caucho.hessian.io.HessianOutput; +import com.caucho.hessian.io.Hessian2Input; +import com.caucho.hessian.io.Hessian2Output; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -15,22 +15,47 @@ public class HessianSerializer { public static byte[] serialize(T obj){ ByteArrayOutputStream os = new ByteArrayOutputStream(); - HessianOutput ho = new HessianOutput(os); + Hessian2Output ho = new Hessian2Output(os); try { ho.writeObject(obj); + ho.flush(); + byte[] result = os.toByteArray(); + return result; } catch (IOException e) { throw new IllegalStateException(e.getMessage(), e); + } finally { + try { + ho.close(); + } catch (IOException e) { + throw new IllegalStateException(e.getMessage(), e); + } + try { + os.close(); + } catch (IOException e) { + throw new IllegalStateException(e.getMessage(), e); + } } - return os.toByteArray(); } public static Object deserialize(byte[] bytes, Class clazz) { ByteArrayInputStream is = new ByteArrayInputStream(bytes); - HessianInput hi = new HessianInput(is); + Hessian2Input hi = new Hessian2Input(is); try { - return hi.readObject(); + Object result = hi.readObject(); + return result; } catch (IOException e) { throw new IllegalStateException(e.getMessage(), e); + } finally { + try { + hi.close(); + } catch (Exception e) { + throw new IllegalStateException(e.getMessage(), e); + } + try { + is.close(); + } catch (IOException e) { + throw new IllegalStateException(e.getMessage(), e); + } } }