With a LogThread as in the example below the user-thread will return as soon as the LogEvent is stored in the buffer.
Depending on how Log4j is used it might not be permitted to create threads (like in an EJB container).
A configuration parameter that controlles if the JDBCAppender should use the thread or not might be useful.
Such configuration is not included below.
LogWorker logThread = new LogWorker(this);
public JDBCAppender() { super(); buffer = new ArrayList(bufferSize); logThread.start(); }
public void append(LoggingEvent event) { buffer.add(event); if (buffer.size() >= bufferSize) logThread.wakeup(); }
class LogWorker extends Thread { JDBCAppender parent; logWorker (JDBCAppender p) { parent = p; } public void run() { while (true) { try { synchronized(this) { wait(); } } catch (InterruptedException e) { } parent.flushBuffer(); } }
public synchronized void wakeup() { notify(); } }
Roland Nygren, Telia Promotor AB
Röstringning: 018 - 18 94 50 (säg: "Roland Nygren" eller "Roland Nygren på mobiltelefon")
Växel: 018 - 18 94 00
Direkt: 018 - 18 92 73
Mobil: 070 - 528 92 73
<http://www.promotor.telia.se/>http://www.promotor.telia.se/
__________________________
Security: Restricted