First, send dozens of small and small packages consecutively (<10 bytes) then, when a 64-byte package is suddenly sent, you will find that Mina will encounter the following error when using Mina to process big data reception:
Org. Apache. Mina. Filter. codec. protocoldecoderexception: Java. NiO. bufferoverflowexception (hexdump: 53 53 00 04)
At org. Apache. Mina. Filter. codec. protocolcodecfilter. messagereceived (protocolcodecfilter. Java: 242)
At org. Apache. Mina. Core. filterchain. defaultiofilterchain. callnextmessagereceived (defaultiofilterchain. Java: 417)
At org. Apache. Mina. Core. filterchain. defaultiofilterchain. Access $1200 (defaultiofilterchain. Java: 47)
At org. Apache. Mina. Core. filterchain. defaultiofilterchain $ entryimpl $1. messagereceived (defaultiofilterchain. Java: 765)
At org. Apache. Mina. Core. filterchain. iofilteradapter. messagereceived (iofilteradapter. Java: 109)
At org. Apache. Mina. Core. filterchain. defaultiofilterchain. callnextmessagereceived (defaultiofilterchain. Java: 417)
At org. Apache. Mina. Core. filterchain. defaultiofilterchain. firemessagereceived (defaultiofilterchain. Java: 410)
At org. Apache. Mina. Core. Polling. abstractpollingioprocessor. Read (abstractpollingioprocessor. Java: 710)
At org. Apache. Mina. Core. Polling. abstractpollingioprocessor. Process (abstractpollingioprocessor. Java: 664)
At org. Apache. Mina. Core. Polling. abstractpollingioprocessor. Process (abstractpollingioprocessor. Java: 653)
At org. Apache. Mina. Core. Polling. abstractpollingioprocessor. Access $600 (abstractpollingioprocessor. Java: 67)
At org. Apache. Mina. Core. Polling. abstractpollingioprocessor $ processor. Run (abstractpollingioprocessor. Java: 1124)
At org. Apache. Mina. util. namepreservingrunnable. Run (namepreservingrunnable. Java: 64)
At java. util. Concurrent. threadpoolexecutor $ worker. runtask (threadpoolexecutor. Java: 885)
At java. util. Concurrent. threadpoolexecutor $ worker. Run (threadpoolexecutor. Java: 907)
At java. Lang. thread. Run (thread. Java: 619)
Caused by: Java. NiO. bufferoverflowexception
At java. NiO. heapbytebuffer. Put (heapbytebuffer. Java: 182)
At org. Apache. Mina. Core. Buffer. abstractiobuffer. Put (abstractiobuffer. Java: 625)
At org. Apache. Mina. Core. Buffer. abstractiobuffer. Put (abstractiobuffer. Java: 1329)
After the analysis of Mina, this is made from the incorrect package length (that is, the length of the packet we send is greater than 64 bytes, but its bytebuffer size is only 64 bytes, this error occurs when we try to read 65th bytes );
Solution:
Acceptor. getsessionconfig (). setreadbuffersize (1024*1024); // sending buffer 1 m
Acceptor. getsessionconfig (). setreceivebuffersize (1024*1024); // The receiving buffer is 1 MB.
In actual application, you can set a reasonable size based on the business data packets.