Current limiting function design

I did a current limiting function a long time ago, and the design was ugly. Today, I saw that the current limiting filter of Log4j2 is very well designed. I spent some time researching it and I feel very good. I may use it again in the future. Let’s summarize it.

 

First of all, let's talk about what the current limiting function is mainly used for? In fact, it is to limit how many times an operation can be performed within a certain period of time.

Log4j2 uses a DelayQueue and a ConcurrentLinkedQueue to develop a filter ( burstFilter ) which elegantly solves this problem.

 

The overall structure is as follows:



 

 

The core logic of the design is as follows:



 

 

The burstFilter initialization sequence is as follows:


 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326273059&siteId=291194637