forked from I2P_Developers/i2p.i2p
* Shutdown:
- Stop I2PThread from starting a new App context at shutdown
- Stop LogWriter from starting a new App context at shutdown
- Have router kill any leftover App context at startup
This commit is contained in:
@@ -20,7 +20,11 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||
*
|
||||
*/
|
||||
public class I2PThread extends Thread {
|
||||
private static volatile Log _log;
|
||||
/**
|
||||
* Non-static to avoid refs to old context in Android.
|
||||
* Probably should just remove all the logging though.
|
||||
*/
|
||||
private volatile Log _log;
|
||||
private static final Set _listeners = new CopyOnWriteArraySet();
|
||||
private String _name;
|
||||
private Exception _createdBy;
|
||||
@@ -61,8 +65,9 @@ public class I2PThread extends Thread {
|
||||
_createdBy = new Exception("Created by");
|
||||
}
|
||||
|
||||
private static void log(int level, String msg) { log(level, msg, null); }
|
||||
private static void log(int level, String msg, Throwable t) {
|
||||
private void log(int level, String msg) { log(level, msg, null); }
|
||||
|
||||
private void log(int level, String msg, Throwable t) {
|
||||
// we cant assume log is created
|
||||
if (_log == null) _log = new Log(I2PThread.class);
|
||||
if (_log.shouldLog(level))
|
||||
@@ -85,7 +90,9 @@ public class I2PThread extends Thread {
|
||||
if (t instanceof OutOfMemoryError)
|
||||
fireOOM((OutOfMemoryError)t);
|
||||
}
|
||||
log(Log.INFO, "Thread finished normally: " + _name);
|
||||
// This creates a new I2PAppContext after it was deleted
|
||||
// in Router.finalShutdown() via RouterContext.killGlobalContext()
|
||||
//log(Log.INFO, "Thread finished normally: " + _name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -656,6 +656,9 @@ public class LogManager {
|
||||
// this could generate out-of-order messages
|
||||
_writer.flushRecords(false);
|
||||
_writer.stopWriting();
|
||||
synchronized (_writer) {
|
||||
_writer.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class LogWriter implements Runnable {
|
||||
private File _currentFile;
|
||||
private final LogManager _manager;
|
||||
|
||||
private boolean _write;
|
||||
private volatile boolean _write;
|
||||
private static final int MAX_DISKFULL_MESSAGES = 8;
|
||||
private int _diskFullMessageCount;
|
||||
|
||||
@@ -55,7 +55,8 @@ class LogWriter implements Runnable {
|
||||
rotateFile();
|
||||
while (_write) {
|
||||
flushRecords();
|
||||
rereadConfig();
|
||||
if (_write)
|
||||
rereadConfig();
|
||||
}
|
||||
//System.err.println("Done writing");
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -191,6 +191,11 @@ public class Router {
|
||||
// Save this in the context for the logger and apps that need it
|
||||
envProps.setProperty("i2p.systemTimeZone", originalTimeZoneID);
|
||||
|
||||
// Make darn sure we don't have a leftover I2PAppContext in the same JVM
|
||||
// e.g. on Android - see finalShutdown() also
|
||||
if (RouterContext.getContexts().isEmpty())
|
||||
RouterContext.killGlobalContext();
|
||||
|
||||
// The important thing that happens here is the directory paths are set and created
|
||||
// i2p.dir.router defaults to i2p.dir.config
|
||||
// i2p.dir.app defaults to i2p.dir.router
|
||||
|
||||
Reference in New Issue
Block a user