Changeset f44a8e4


Ignore:
Timestamp:
Jun 1, 2019 2:05:40 PM (10 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
0a774c6c
Parents:
1109331
Message:

Tunnels: Ensure GW Pumper threads stop on Android

File:
1 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/tunnel/TunnelGatewayPumper.java

    r1109331 rf44a8e4  
    77import java.util.List;
    88import java.util.Set;
     9import java.util.concurrent.CopyOnWriteArrayList;
     10
    911import net.i2p.router.RouterContext;
    1012import net.i2p.util.I2PThread;
     
    2426    private final Set<PumpedTunnelGateway> _wantsPumping;
    2527    private final Set<PumpedTunnelGateway> _backlogged;
     28    private final List<Thread> _threads;
    2629    private volatile boolean _stop;
    2730    private static final int MIN_PUMPERS = 1;
     
    4043        _wantsPumping = new LinkedHashSet<PumpedTunnelGateway>(16);
    4144        _backlogged = new HashSet<PumpedTunnelGateway>(16);
     45        _threads = new CopyOnWriteArrayList<Thread>();
    4246        if (ctx.getBooleanProperty("i2p.dummyTunnelManager")) {
    4347            _pumpers = 1;
     
    4650            _pumpers = (int) Math.max(MIN_PUMPERS, Math.min(MAX_PUMPERS, 1 + (maxMemory / (32*1024*1024))));
    4751        }
    48         for (int i = 0; i < _pumpers; i++)
    49             new I2PThread(this, "Tunnel GW pumper " + (i+1) + '/' + _pumpers, true).start();
     52        for (int i = 0; i < _pumpers; i++) {
     53            Thread t = new I2PThread(this, "Tunnel GW pumper " + (i+1) + '/' + _pumpers, true);
     54            _threads.add(t);
     55            t.start();
     56        }
    5057    }
    5158
     
    6269            } catch (InterruptedException ie) {}
    6370        }
     71        for (Thread t : _threads) {
     72            t.interrupt();
     73        }
     74        _threads.clear();
    6475        _wantsPumping.clear();
    6576    }
     
    7586   
    7687    public void run() {
     88        try {
     89            run2();
     90        } finally {
     91            _threads.remove(Thread.currentThread());
     92        }
     93    }
     94
     95    private void run2() {
    7796        PumpedTunnelGateway gw = null;
    7897        List<PendingGatewayMessage> queueBuf = new ArrayList<PendingGatewayMessage>(32);
Note: See TracChangeset for help on using the changeset viewer.