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
OutOfMemoryErroron the client side. To avoid that, you have to stop writing ifChannel.isWritable()returnsfalse. You will be notified with achannelInterestOpsChangedevent when the status ofChannel.writable' changes. Then, you can check again ifChannel.isWritable()returnstrue` and continue writing.If it is OK to discard the pending data, I would simply not call
Channel.write()ifChannel.isWritable()returnsfalse.You can configure when
Channel.writableproperty changes with the watermark properties provided inNioSocketChannelConfig. Also, please take a look into the ‘discard’ example that uses this technique.