手动释放对象

This commit is contained in:
Guoqs
2024-12-28 11:36:35 +08:00
parent 2ff36a6ed7
commit 458c216a6d

View File

@@ -8,6 +8,7 @@ import com.jsowell.netty.service.electricbicycles.EBikeBusinessService;
import io.netty.buffer.ByteBuf;
import io.netty.channel.*;
import io.netty.handler.timeout.ReadTimeoutException;
import io.netty.util.ReferenceCountUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -60,6 +61,7 @@ public class ElectricBicyclesServerHandler extends ChannelInboundHandlerAdapter
*/
@Override
public void channelRead(ChannelHandlerContext ctx, Object message) throws Exception {
try {
byte[] msg = (byte[]) message;
// 处理数据
byte[] response = eBikeService.process(msg, ctx);
@@ -79,6 +81,10 @@ public class ElectricBicyclesServerHandler extends ChannelInboundHandlerAdapter
// BytesUtil.binary(response, 16));
// }
}
} finally {
ReferenceCountUtil.release(message);
}
}
/**