Simple version of the record about the last month implemented a communication center to push the process of two communication centers.

     Last month I appeared in the communications center, you can put in storage mysql5.7, but the customer can not be pushed to a third-party API, I decided to split into three communications center, a communications center dedicated only to receive and forward information to another two communication centers,

The other two communication centers are so arranged a special protocol parsing National Hydrological and storage operation, another communications center analyzing hydrological agreement after it is pushed to a third-party API. Explain my program is based netty communications framework.

Then came an exception:io.netty.util.IllegalReferenceCountException: refCnt: 0

Through the network to know why the query is:

This is because of the reference counter Netty, Netty 4 since the beginning of the life cycle of the object referenced by their count (reference counts) management, rather than by the garbage collector (garbage collector) to manage. ByteBuf is most noteworthy, it uses the reference count to improve performance of memory allocation and release of memory.

After we create ByteBuf object, its reference count is 1, when you release (release) the reference count object, its reference count by 1, if the reference count is 0, the reference count object will be to release (deallocate), and returns the object pool.

The main reason is the time to be forwarded to the two communications centers after my first special transit center to receive information RTU communication equipment, the first hop is not a problem, this time a series of methods such as call ByteBuf ctx.write the release method, which decrements the reference count is zero, and when the second forwarding on the reported abnormal.

the solution:

.retain (); // we can call ByteBuf.retain () the reference count is incremented

.duplicate (); // copy the current object, the object of copying shared buffer after the previous object and maintain their own independent index

Took the communication center is a push (forward) thought the other two communication centers:

As the business is to process the information sent from the RTU device coupled pushed to a third-party API, if the device is not connected up, three communication centers also have their own interconnection.

Ideas are as follows:

Part I: can not customize your own header and 7E7E hydrological like it.

Second part: arranged two bytes indicate the remaining length of the message.

Part III: hydrological two bytes packets length.

Part IV: Hydrology content packets (if the length of the third portion is greater than zero).

Part V: heartbeat information between the communication center (third portion if the length is equal to zero).

After investigation found that third-party push the program I use to hang after twelve days just do not push, and push to replace another program. After a month, the program has stabilized.

Guess you like

Origin www.cnblogs.com/yebinghuai/p/12037906.html