我编写了以下方法来检查记录器的工作功能,
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
我的问题是,程序控制会等到记录器完成它的过程吗
(即根据配置将消息写入日志文件),
或者 logger 将控制权返回给调用代码后独立执行。
(从上面的代码可以看出logger需要一些时间,但我的想法是在这段时间内无法完成文件操作)