JobQueueRunner: Don't call System.exit() on OOM,

let the shutdown progress normally;
Make it an I2PThread instead of a Runner so we can
call fireOOM() for consistent logging (ticket #1549)
Router: Don't add OOM listener on Android so
we don't hang onto the context
This commit is contained in:
zzz
2015-04-28 21:57:13 +00:00
parent cb50c1bd8b
commit f16927f316
3 changed files with 17 additions and 23 deletions

View File

@@ -493,9 +493,8 @@ public class JobQueue {
for (int i = _queueRunners.size(); i < numThreads; i++) {
JobQueueRunner runner = new JobQueueRunner(_context, i);
_queueRunners.put(Integer.valueOf(i), runner);
Thread t = new I2PThread(runner, "JobQueue " + _runnerId.incrementAndGet() + '/' + numThreads, false);
//t.setPriority(I2PThread.MAX_PRIORITY-1);
t.start();
runner.setName("JobQueue " + _runnerId.incrementAndGet() + '/' + numThreads);
runner.start();
}
} else if (_queueRunners.size() == numThreads) {
for (JobQueueRunner runner : _queueRunners.values()) {

View File

@@ -1,9 +1,11 @@
package net.i2p.router;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
import net.i2p.util.SystemVersion;
/** a do run run run a do run run */
class JobQueueRunner implements Runnable {
class JobQueueRunner extends I2PThread {
private final Log _log;
private final RouterContext _context;
private volatile boolean _keepRunning;
@@ -12,7 +14,7 @@ class JobQueueRunner implements Runnable {
private volatile Job _lastJob;
private volatile long _lastBegin;
private volatile long _lastEnd;
private volatile int _state;
//private volatile int _state;
public JobQueueRunner(RouterContext context, int id) {
_context = context;
@@ -23,7 +25,7 @@ class JobQueueRunner implements Runnable {
//_state = 1;
}
final int getState() { return _state; }
//final int getState() { return _state; }
public Job getCurrentJob() { return _currentJob; }
public Job getLastJob() { return _lastJob; }
@@ -115,14 +117,12 @@ class JobQueueRunner implements Runnable {
//if ( (jobNum % 10) == 0)
// System.gc();
} catch (Throwable t) {
if (_log.shouldLog(Log.CRIT))
_log.log(Log.CRIT, "WTF, error running?", t);
_log.log(Log.CRIT, "WTF, error running?", t);
}
}
//_state = 16;
if (_context.router().isAlive())
if (_log.shouldLog(Log.CRIT))
_log.log(Log.CRIT, "Queue runner " + _id + " exiting");
_log.log(Log.CRIT, "Queue runner " + _id + " exiting");
_context.jobQueue().removeRunner(_id);
//_state = 17;
}
@@ -134,21 +134,15 @@ class JobQueueRunner implements Runnable {
_currentJob.runJob();
//_state = 19;
} catch (OutOfMemoryError oom) {
//_state = 20;
try {
if (_log.shouldLog(Log.CRIT))
_log.log(Log.CRIT, "Router ran out of memory, shutting down", oom);
_log.log(Log.CRIT, _currentJob.getClass().getName());
_context.router().shutdown(Router.EXIT_OOM);
} catch (Throwable t) {
System.err.println("***Router ran out of memory, shutting down hard");
}
try { Thread.sleep(1000); } catch (InterruptedException ie) {}
System.exit(-1);
if (SystemVersion.isAndroid())
_context.router().shutdown(Router.EXIT_OOM);
else
fireOOM(oom);
} catch (Throwable t) {}
} catch (Throwable t) {
//_state = 21;
if (_log.shouldLog(Log.CRIT))
_log.log(Log.CRIT, "Error processing job [" + _currentJob.getName()
_log.log(Log.CRIT, "Error processing job [" + _currentJob.getName()
+ "] on thread " + _id + ": " + t.getMessage(), t);
//if (_log.shouldLog(Log.ERROR))
// _log.error("The above job was enqueued by: ", _currentJob.getAddedBy());

View File

@@ -559,7 +559,8 @@ public class Router implements RouterClock.ClockShiftListener {
try {
Runtime.getRuntime().addShutdownHook(_shutdownHook);
} catch (IllegalStateException ise) {}
I2PThread.addOOMEventListener(_oomListener);
if (!SystemVersion.isAndroid())
I2PThread.addOOMEventListener(_oomListener);
_context.keyManager().startup();