Java – reduce the recording of the same exception

Is there any smart way to reduce the record of "equal" exceptions?

For example:

java.lang.IllegalArgumentException: Wrong parameter,should be a float from 0 to 100
at com.test.Foo.setAmount(Foo.java:93)
at com.test.Bar.setAmounts(Bar.java:39)
at com.test.Bar2.init(Bar2.java:152)
at java.awt.event.InvocationEvent.dispatch(UnkNown Source) [na:1.7.0_65]
at java.awt.EventQueue.dispatchEventImpl(UnkNown Source) [na:1.7.0_65]
at java.awt.EventQueue.access$200(UnkNown Source) [na:1.7.0_65]
at java.awt.EventQueue$3.run(UnkNown Source) [na:1.7.0_65]
at java.awt.EventQueue$3.run(UnkNown Source) [na:1.7.0_65]
at java.security.AccessController.doPrivileged(Native Method) [na:1.7.0_65]
at java.security.ProtectionDomain$1.doIntersectionPrivilege(UnkNown Source) [na:1.7.0_65]
at java.awt.EventQueue.dispatchEvent(UnkNown Source) [na:1.7.0_65]
at java.awt.EventDispatchThread.pumpOneEventForFilters(UnkNown Source) [na:1.7.0_65]
at java.awt.EventDispatchThread.pumpEventsForFilter(UnkNown Source) [na:1.7.0_65]
at java.awt.EventDispatchThread.pumpEventsForHierarchy(UnkNown Source) [na:1.7.0_65]
at java.awt.EventDispatchThread.pumpEvents(UnkNown Source) [na:1.7.0_65]
at java.awt.EventDispatchThread.pumpEvents(UnkNown Source) [na:1.7.0_65]
at java.awt.EventDispatchThread.run(UnkNown Source) [na:1.7.0_65]

Under certain circumstances, this exception can be thrown 90 times per second We use the AWT handler to log exceptions, which can "freeze" all swing applications

The first solution I think of is to record exceptions in different threads, but such an approval may be a real hell in future debugging

The second idea is to put exceptions in the weakhashmap and record exceptions only the first time they occur I don't know how to execute exception equals fast enough

Solution

If logback is used, a filter named duplicatemessagefilter will discard messages after repeated for a period of time

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>