开发者

Cost of creating exception compared to cost of logging it

Just wonder how much cost to raise a java exception (or to call native fillInStackTrace() of Throwable) compared to what it cost to log it with log4j (in a file, with production hard drive)...

Asking myself, when exceptions are raised, does it worth to often log them even if they are not necessary significant... (i work in a hi开发者_开发技巧gh load environment)

Thanks


I assume from your jee6 tag that you are specifically talking about exceptions in Java.

If you have so many exceptions that logging them is a performance issue, you should probably reconsider your use of exceptions.

Exceptions should be used for exceptional situations. If you are doing something so frequently that the logging becomes a performance issue, it's probably not an exceptional situation.

To answer your specific question: logging will be several orders of magnitude slower. If you know that you won't need the exceptions logged then you should be able to improve the performance of your application by not logging them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜