Java concurrent logging to file -
Java concurrent logging to file -
i'm writting logger (e.g. using java logger) can log activities (info, errors) file. (static) logger class used several threads , processes.
if have 1 log file threads blocked, right? 1 thread can write file?
another solution have each thread own log file, bit messy.
therefore, tought first keeping log in stream (perhaps each thread one) , @ end of programme write file.
is best way? how can accomplish this?
you can seek writing file @ end of program, might utilize lot of memory, , loggers need implemented they'll still log most/all of info in case of programme crash or other unexpected termination.
as alternative, can utilize concurrent queue logged messages, e.g. linkedblockingqueue or concurrentlinkedqueue, multiple threads write messages queue , single thread reads queue , writes messages file. blockingqueue logging thread can phone call take or poll(timeout, timeunit) on queue, causing thread sleep until messages becomes available; concurrentlinkedqueue can have logging thread sleep for, say, 10 seconds, wake up, flush queue file, , go sleep 10 seconds. in either case threads generating logged messages won't block.
java logging concurrency error-logging
Comments
Post a Comment