简体   繁体   中英

Java, non-blocking console output

I have an interface which methods are getting called in the multiple threads:

interface Handler{
 void readedMessage(long atTime);
 void recievedMessage(long atTime);
 void deletedMessage(long atTime);
}

And of course I don't want these callings to block my threads, what I want is just to print something on console where these methods are getting called, to do that I need to implement this interface, what's the best way to do it: are Java loggers provide such functionality or I should make a ThreadExecutor with these prints getting called? It's a simple maven project which will be used as library, so wouldn't it be unecessary to add logger? And which one provides such functionality (googling didn't help unfortunately).

are Java loggers provide such functionality?

Yes, Log4j allows asynchronous writes only by activating them in the runtime, eg

-Dlog4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector

For further information Asynchronous Loggers for Low-Latency Logging

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM