简体   繁体   English

Java,非阻塞控制台输出

[英]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?当然,我不希望这些调用阻塞我的线程,我想要的只是在调用这些方法的控制台上打印一些东西,为此我需要实现这个接口,最好的方法是什么: Java 记录器是否提供了这样的功能,或者我应该制作一个 ThreadExecutor 来调用这些打印? It's a simple maven project which will be used as library, so wouldn't it be unecessary to add logger?这是一个简单的maven项目,将用作库,所以添加记录器不是不必要的吗? And which one provides such functionality (googling didn't help unfortunately).哪一个提供了这样的功能(不幸的是,谷歌搜索没有帮助)。

are Java loggers provide such functionality? Java 记录器是否提供这样的功能?

Yes, Log4j allows asynchronous writes only by activating them in the runtime, eg是的,Log4j 只允许在运行时激活异步写入,例如

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

For further information Asynchronous Loggers for Low-Latency Logging有关详细信息,用于低延迟日志记录的异步记录器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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