Changeset 890ad25 for router


Ignore:
Timestamp:
Jan 30, 2017 10:05:43 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
82d812c
Parents:
7cb5dab
Message:

Router: Run shutdown tasks in parallel,
increase max time for shutdown tasks (ticket #1893)
i2psnark: Remove most delay between announces at shutdown

File:
1 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/Router.java

    r7cb5dab r890ad25  
    1414import java.util.Collection;
    1515import java.util.Collections;
     16import java.util.LinkedList;
    1617import java.util.List;
    1718import java.util.Map;
     
    122123    public static final String UPDATE_FILE = "i2pupdate.zip";
    123124       
     125    private static final int SHUTDOWN_WAIT_SECS = 60;
     126
    124127    private static final String originalTimeZoneID;
    125128    static {
     
    956959                             _context.bandwidthLimiter().getOutboundKBytesPerSecond());
    957960        bwLim = (int)(bwLim * getSharePercentage());
    958         if (_log.shouldLog(Log.INFO))
    959             _log.info("Adding capabilities w/ bw limit @ " + bwLim, new Exception("caps"));
    960961       
    961962        String force = _context.getProperty(PROP_FORCE_BWCLASS);
     
    12111212        // Run the shutdown hooks first in case they want to send some goodbye messages
    12121213        // Maybe we need a delay after this too?
     1214        LinkedList<Thread> tasks = new LinkedList<Thread>();
    12131215        for (Runnable task : _context.getShutdownTasks()) {
    12141216            //System.err.println("Running shutdown task " + task.getClass());
     
    12201222                t.setDaemon(true);
    12211223                t.start();
    1222                 try {
    1223                     t.join(10*1000);
    1224                 } catch (InterruptedException ie) {}
    1225                 if (t.isAlive())
    1226                     _log.logAlways(Log.WARN, "Shutdown task took more than 10 seconds to run: " + task.getClass());
     1224                tasks.add(t);
    12271225            } catch (Throwable t) {
    12281226                _log.log(Log.CRIT, "Error running shutdown task", t);
     1227            }
     1228        }
     1229        long waitSecs = SHUTDOWN_WAIT_SECS;
     1230        if (SystemVersion.isARM())
     1231            waitSecs *= 2;
     1232        final long maxWait = System.currentTimeMillis() + (waitSecs *1000);
     1233        Thread th;
     1234        while ((th = tasks.poll()) != null) {
     1235            long toWait = maxWait - System.currentTimeMillis();
     1236            if (toWait <= 0) {
     1237                _log.logAlways(Log.WARN, "Shutdown tasks took more than " + waitSecs + " seconds to run");
     1238                tasks.clear();
     1239                break;
     1240            }
     1241            try {
     1242                th.join(toWait);
     1243            } catch (InterruptedException ie) {}
     1244            if (th.isAlive()) {
     1245                _log.logAlways(Log.WARN, "Shutdown task took more than " + waitSecs + " seconds to run: " + th.getName());
     1246                tasks.clear();
     1247                break;
     1248            } else if (_log.shouldInfo()) {
     1249                _log.info("Shutdown task complete: " + th.getName());
    12291250            }
    12301251        }
Note: See TracChangeset for help on using the changeset viewer.