日期:2014-05-20 浏览次数:20757 次
public class Log4jThread extends Thread { private File file; private long lastModified; private final long millis = 10 * 1000L; public Log4jThread(String path) { setName(Log4jThread.class.getSimpleName()); file = new File(path); lastModified = file.lastModified(); PropertyConfigurator.configure(path); } public void run() { while(true) { try { sleep(millis); if(file.lastModified() != lastModified) { //PropertyConfigurator.configure(file.getCanonicalPath()); DOMConfigurator.configure(file.getCanonicalPath()); lastModified = file.lastModified(); System.out.println("Info: The log4j.properties is reload!"); } } catch(InterruptedException e) { System.err.println("Error: The log4j thread is interrupted!"); } catch(IOException e) { System.err.println("Error: Cann't find '" + file.getName() + "'!"); } } } }