Added a wakeup() method that allows us to ping the Logger thread to resume
running immediately. Also decreased the sleep interval to 250 millis, so logging output should be more fluent now. Reformatted innger GZipper class.
This commit is contained in:
parent
a080342079
commit
fd74552857
1 changed files with 42 additions and 28 deletions
|
@ -280,7 +280,6 @@ public final class Logger {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a list of all active Loggers
|
* Return a list of all active Loggers
|
||||||
*/
|
*/
|
||||||
|
@ -290,6 +289,14 @@ public final class Logger {
|
||||||
return (List) loggers.clone ();
|
return (List) loggers.clone ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify the runner thread that it should wake up and run.
|
||||||
|
*/
|
||||||
|
public static void wakeup () {
|
||||||
|
if (runner != null)
|
||||||
|
runner.wakeup ();
|
||||||
|
}
|
||||||
|
|
||||||
private static void rotateAllLogs () {
|
private static void rotateAllLogs () {
|
||||||
int nloggers = loggers.size();
|
int nloggers = loggers.size();
|
||||||
for (int i=nloggers-1; i>=0; i--) {
|
for (int i=nloggers-1; i>=0; i--) {
|
||||||
|
@ -307,7 +314,7 @@ public final class Logger {
|
||||||
*/
|
*/
|
||||||
static class Runner extends Thread {
|
static class Runner extends Thread {
|
||||||
|
|
||||||
public void run () {
|
public synchronized void run () {
|
||||||
long nextMidnight = nextMidnight ();
|
long nextMidnight = nextMidnight ();
|
||||||
while (runner == this && !isInterrupted ()) {
|
while (runner == this && !isInterrupted ()) {
|
||||||
if (nextMidnight < System.currentTimeMillis ()) {
|
if (nextMidnight < System.currentTimeMillis ()) {
|
||||||
|
@ -327,12 +334,19 @@ public final class Logger {
|
||||||
System.err.println ("Error in Logger main loop: "+x);
|
System.err.println ("Error in Logger main loop: "+x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// if there are no active logs, exit logger thread
|
||||||
|
if (loggers.size() == 0)
|
||||||
|
return;
|
||||||
try {
|
try {
|
||||||
sleep (500);
|
wait (250);
|
||||||
} catch (InterruptedException ix) {}
|
} catch (InterruptedException ix) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized void wakeup () {
|
||||||
|
notifyAll ();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue