Hitting an OutMemoryError connecting to 3rd party server which cannot process requests fast enough.
Tried NioClientSocketChannelFactory to pass in the executor service with the bounded queue and discard policy (ThreadPoolExecutor.DiscardPolicy) but still got OutOfMemoryError.
What am I missing?
Thanks
If your client-side Netty channel's write buffer fills up and the server is not reading it fast enough, you will see OutOfMemoryError
on the client side. To avoid that, you have to stop writing if Channel.isWritable()
returns false
. You will be notified with a channelInterestOpsChanged
event when the status of Channel.writable' changes. Then, you can check again if
Channel.isWritable()returns
true` and continue writing.
If it is OK to discard the pending data, I would simply not call Channel.write()
if Channel.isWritable()
returns false
.
You can configure when Channel.writable
property changes with the watermark properties provided in NioSocketChannelConfig
. Also, please take a look into the 'discard' example that uses this technique.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With