1

Heyho,

ByteBuffers as well as netty's ByteBuff use indices to store where they currently "are". At the start of my application I load multiple files in ByteBuffers/ByteBuffs to read later from those. Also the bytebuffers are immutable after loading. My problem is now that multiple clients should be able to read from those byte buffers, but because they use the same reader/writer indices it won't work. Is there a easy way of maintaining the indices maybe per thread? Does netty have some "tools" to achive this?

I've already read that nio ByteBuffers do not support multiple threads, but is this also true if you only read from them?

Basically I'm only looking for a way to send data, which is stored in memory, very fast over netty.

1 Answer 1

5

You can call duplicate on the ByteBuf for every new Thread and use the returned ByteBuf. Those will share the same content but not the same indices.

ByteBuf duplicate = ByteBuf.duplicate();
Sign up to request clarification or add additional context in comments.

2 Comments

For my netty buffers I could use Allocator.wrappedBuffer(...) to fix the indices. So reading from multiple threads should be safe, right?
As long as you use get*() and not read*() yes, as read*() will increase the readerIndex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.