You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public static void main(String[] args) throws Exception {
Eventloop eventloop = Eventloop.create().withCurrentThread();
SimpleServer server = SimpleServer.create(eventloop, new Consumer<AsyncTcpSocket>() {
@Override
public void accept(AsyncTcpSocket socket) {
// readData(socket);
BinaryChannelSupplier
.of(ChannelSupplier.ofSocket(socket))
.decodeStream(customDecoder(1024))
.streamTo(ChannelConsumer.ofConsumer((data) -> {
//read data....
//should i call data.recycle() after read data?
data.recycle(); // Is this right?
}));
}
});
server.withListenPort(PORT);
server.listen();
System.out.println("Server is running");
System.out.println("You can connect from telnet with command: telnet localhost 9922 or by running csp.TcpClientExample");
eventloop.run();
}
"To make everything consistent, ActiveJ relies on the concept of ‘ownership’ (like in Rust language) - after allocation, the components pass a byteBuf from one to another, until the last ‘owner’ recycles it to ByteBufPool."
after read data? should call ByteBuf.recycle()? how about when client disconnect, shoudl activej recycle all buf have been used?
The text was updated successfully, but these errors were encountered:
azzahrah
changed the title
When call ByteBuf.recycle after read data?
Should call ByteBuf.recycle() after read data?
Feb 2, 2021
Hello, @azzahrah
Yes, you should recycle a ByteBuf once you have read data from it and not planning to use it anymore. This way you will ease Java’s garbage collection and overall memory pressure. If you do not recycle a ByteBuf, it will still be collected during GC (if there are no references to the ByteBuf).
ActiveJ recycles all of the internal ByteBufs once they are not needed (e.g. connection closes, component shutdowns).
Should we recycle after read incoming data
Main App
"To make everything consistent, ActiveJ relies on the concept of ‘ownership’ (like in Rust language) - after allocation, the components pass a byteBuf from one to another, until the last ‘owner’ recycles it to ByteBufPool."
after read data? should call ByteBuf.recycle()? how about when client disconnect, shoudl activej recycle all buf have been used?
The text was updated successfully, but these errors were encountered: