我在我的应用上遇到过behviuore。它是多线程应用程序。线程访问共享的concurrentlinkedqueue对象。有时系统加载。系统在下面的部分很慢,有时在两行日志之间需要超过120毫秒。 任何解释都可能有所帮助
class A {
method aA (){
// log line here
system.out.println("current time1" +system.getcurrentmillisecond())
bb(queue);
}
method bb (concurrentlinkedqueue queue){
// logs here
system.out.println("current time2" +system.getcurrentmillisecond())
}
}
答案 0 :(得分:1)
经验法则是,如果您正在使用实时应用程序,则无法信任写入日志的时间,因为您的系统速度非常快且LOG无论如何都是异步的。
使用此:
long startTime = System.currentTimeInMillis();
// do your task
long endTime = System.currentTimeInMillis();
Logger.info(endTime - startTime);