与concurrentlinkedqueue相关的java性能

时间:2013-09-30 08:55:16

标签: java performance

我在我的应用上遇到过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())


}


}

1 个答案:

答案 0 :(得分:1)

经验法则是,如果您正在使用实时应用程序,则无法信任写入日志的时间,因为您的系统速度非常快且LOG无论如何都是异步的。

使用此:

long startTime = System.currentTimeInMillis();

// do your task
long endTime = System.currentTimeInMillis();

Logger.info(endTime - startTime);