2
我写检查记录仪的工作功能的方法如下,Java的记录器执行的方法
package test;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
public class test1{
private static Logger logger = Logger.getLogger(test1.class);
public static void main(String args[])
{
System.out.println("time 1 "+System.currentTimeMillis());
logger.log(Level.INFO,"Eror "+System.currentTimeMillis());
System.out.println("time 2 "+System.currentTimeMillis());
logger.log(Level.INFO,"Eror "+System.currentTimeMillis());
logger.log(Level.INFO,"Eror "+System.currentTimeMillis());
logger.log(Level.INFO,"Eror "+System.currentTimeMillis());
logger.log(Level.INFO,"Eror "+System.currentTimeMillis());
logger.log(Level.INFO,"Eror "+System.currentTimeMillis());
System.out.println("time 3 "+System.currentTimeMillis());
System.out.println("time 4 "+System.currentTimeMillis());
System.out.println("time 5 "+System.currentTimeMillis());
}
}
,我得到了如下输出,
time 1 1367325027239
time 2 1367325027247
Apr 30, 2013 6:00:27 PM test.test1 main
INFO: Eror 1367325027239
Apr 30, 2013 6:00:27 PM test.test1 main
INFO: Eror 1367325027247
Apr 30, 2013 6:00:27 PM test.test1 main
INFO: Eror 1367325027248
Apr 30, 2013 6:00:27 PM test.test1 main
INFO: Eror 1367325027249
Apr 30, 2013 6:00:27 PM test.test1 main
INFO: Eror 1367325027250
Apr 30, 2013 6:00:27 PM test.test1 main
INFO: Eror 1367325027250
time 3 1367325027251
time 4 1367325027251
time 5 1367325027251
我的问题是,在程序控制器等待记录器完成其过程
(即根据配置将消息写入日志文件),
或者记录器将控件返回到调用代码后将独立执行。
(从上面的代码可以看出,记录仪需要一些时间, 但我的想法是,在这段时间内的文件操作无法完成)
这似乎完全取决于该记录器如何配置。它可能是异步的(也是缓冲的)。 – Thilo 2013-04-30 12:45:22
我没有在属性文件中配置同步或异步。 – Aravind 2013-04-30 12:54:55