Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does log4j uses NIO for writing data to file?

Tags:

java

log4j

nio

It seems to be pretty fast already and i was just wondering if anyone knows if its using NIO. I tried searching the whole source code for NIO (well, its kind of way to search :) lol); but did not hit anything. Also, If its not using NIO; do you think its worthwhile to modify log4j to use NIO also to make it more faster? Any pointers advises and links to some resources would be lot helpful.

like image 935
vpram86 Avatar asked Feb 27 '23 17:02

vpram86


2 Answers

Also, If its not using NIO; do you think its worthwhile to modify of log4j to use NIO also to make it more faster?

No, unless logging is a significant part of your application's activities, in which case there is usually something wrong.

You seem to be under the impression that NIO 'is faster', but this is not true in general. Just try creating two files, one with standard IO and one with NIO, writing a bunch of data to them and closing them. You'll see the performance hardly differs. NIO will only perform better in certain use cases; most usually the case of many connections.

like image 148
Confusion Avatar answered Mar 01 '23 06:03

Confusion


Check out the FileAppender source. Pretty much just standard java.io.

like image 21
krock Avatar answered Mar 01 '23 08:03

krock