more static atomics

This commit is contained in:
zzz
2013-11-17 15:03:10 +00:00
parent 1d4190734d
commit 7e3e08532f
7 changed files with 28 additions and 20 deletions

View File

@ -25,6 +25,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import net.i2p.I2PAppContext; import net.i2p.I2PAppContext;
import net.i2p.util.I2PAppThread; import net.i2p.util.I2PAppThread;
@ -44,8 +45,8 @@ class PeerConnectionOut implements Runnable
// Contains Messages. // Contains Messages.
private final List<Message> sendQueue = new ArrayList(); private final List<Message> sendQueue = new ArrayList();
private static long __id = 0; private static final AtomicLong __id = new AtomicLong();
private long _id; private final long _id;
long lastSent; long lastSent;
@ -53,7 +54,7 @@ class PeerConnectionOut implements Runnable
{ {
this.peer = peer; this.peer = peer;
this.dout = dout; this.dout = dout;
_id = ++__id; _id = __id.incrementAndGet();
lastSent = System.currentTimeMillis(); lastSent = System.currentTimeMillis();
} }

View File

@ -55,7 +55,7 @@ public class I2PTunnelRunner extends I2PAppThread implements I2PSocket.SocketErr
private long totalSent; private long totalSent;
private long totalReceived; private long totalReceived;
private volatile long __forwarderId; private static final AtomicLong __forwarderId = new AtomicLong();
public I2PTunnelRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialI2PData, public I2PTunnelRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialI2PData,
List<I2PSocket> sockList) { List<I2PSocket> sockList) {
@ -98,7 +98,6 @@ public class I2PTunnelRunner extends I2PAppThread implements I2PSocket.SocketErr
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
_log.info("I2PTunnelRunner started"); _log.info("I2PTunnelRunner started");
_runnerId = __runnerId.incrementAndGet(); _runnerId = __runnerId.incrementAndGet();
__forwarderId = i2ps.hashCode();
setName("I2PTunnelRunner " + _runnerId); setName("I2PTunnelRunner " + _runnerId);
start(); start();
} }
@ -312,7 +311,7 @@ public class I2PTunnelRunner extends I2PAppThread implements I2PSocket.SocketErr
_toI2P = toI2P; _toI2P = toI2P;
direction = (toI2P ? "toI2P" : "fromI2P"); direction = (toI2P ? "toI2P" : "fromI2P");
_cache = ByteCache.getInstance(32, NETWORK_BUFFER_SIZE); _cache = ByteCache.getInstance(32, NETWORK_BUFFER_SIZE);
setName("StreamForwarder " + _runnerId + "." + (++__forwarderId)); setName("StreamForwarder " + _runnerId + '.' + __forwarderId.incrementAndGet());
start(); start();
} }

View File

@ -7,6 +7,7 @@
package net.i2p.i2ptunnel.socks; package net.i2p.i2ptunnel.socks;
import java.net.Socket; import java.net.Socket;
import java.util.concurrent.atomic.AtomicInteger;
import net.i2p.client.streaming.I2PSocket; import net.i2p.client.streaming.I2PSocket;
import net.i2p.i2ptunnel.I2PTunnel; import net.i2p.i2ptunnel.I2PTunnel;
@ -30,7 +31,7 @@ import net.i2p.util.Log;
*/ */
public class I2PSOCKSIRCTunnel extends I2PSOCKSTunnel { public class I2PSOCKSIRCTunnel extends I2PSOCKSTunnel {
private static int __clientId = 0; private static final AtomicInteger __clientId = new AtomicInteger();
/** @param pkf private key file name or null for transient key */ /** @param pkf private key file name or null for transient key */
public I2PSOCKSIRCTunnel(int localPort, Logging l, boolean ownDest, EventDispatcher notifyThis, I2PTunnel tunnel, String pkf) { public I2PSOCKSIRCTunnel(int localPort, Logging l, boolean ownDest, EventDispatcher notifyThis, I2PTunnel tunnel, String pkf) {
@ -50,11 +51,12 @@ public class I2PSOCKSIRCTunnel extends I2PSOCKSTunnel {
Socket clientSock = serv.getClientSocket(); Socket clientSock = serv.getClientSocket();
I2PSocket destSock = serv.getDestinationI2PSocket(this); I2PSocket destSock = serv.getDestinationI2PSocket(this);
StringBuffer expectedPong = new StringBuffer(); StringBuffer expectedPong = new StringBuffer();
int id = __clientId.incrementAndGet();
Thread in = new I2PAppThread(new IrcInboundFilter(clientSock, destSock, expectedPong, _log), Thread in = new I2PAppThread(new IrcInboundFilter(clientSock, destSock, expectedPong, _log),
"SOCKS IRC Client " + (++__clientId) + " in", true); "SOCKS IRC Client " + id + " in", true);
in.start(); in.start();
Thread out = new I2PAppThread(new IrcOutboundFilter(clientSock, destSock, expectedPong, _log), Thread out = new I2PAppThread(new IrcOutboundFilter(clientSock, destSock, expectedPong, _log),
"SOCKS IRC Client " + __clientId + " out", true); "SOCKS IRC Client " + id + " out", true);
out.start(); out.start();
} catch (SOCKSException e) { } catch (SOCKSException e) {
if (_log.shouldLog(Log.WARN)) if (_log.shouldLog(Log.WARN))

View File

@ -3,6 +3,7 @@ package net.i2p.client;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import net.i2p.I2PAppContext; import net.i2p.I2PAppContext;
import net.i2p.data.Destination; import net.i2p.data.Destination;
@ -31,11 +32,11 @@ class MessageState {
private boolean _cancelled; private boolean _cancelled;
private final long _created; private final long _created;
private static long __stateId = 0; private static final AtomicLong __stateId = new AtomicLong();
private long _stateId; private final long _stateId;
public MessageState(I2PAppContext ctx, long nonce, String prefix) { public MessageState(I2PAppContext ctx, long nonce, String prefix) {
_stateId = ++__stateId; _stateId = __stateId.incrementAndGet();
_context = ctx; _context = ctx;
_log = ctx.logManager().getLog(MessageState.class); _log = ctx.logManager().getLog(MessageState.class);
_nonce = nonce; _nonce = nonce;

View File

@ -24,6 +24,7 @@ import java.util.Set;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import net.i2p.I2PAppContext; import net.i2p.I2PAppContext;
@ -738,11 +739,12 @@ public class LogManager {
_consoleBuffer.clear(); _consoleBuffer.clear();
} }
private static int __id = 0; private static final AtomicInteger __id = new AtomicInteger();
private class ShutdownHook extends Thread { private class ShutdownHook extends Thread {
private int _id; private final int _id;
public ShutdownHook() { public ShutdownHook() {
_id = ++__id; _id = __id.incrementAndGet();
} }
@Override @Override
public void run() { public void run() {

View File

@ -1,5 +1,7 @@
package net.i2p.router.networkdb.kademlia; package net.i2p.router.networkdb.kademlia;
import java.util.concurrent.atomic.AtomicInteger;
import net.i2p.data.Hash; import net.i2p.data.Hash;
import net.i2p.data.RouterInfo; import net.i2p.data.RouterInfo;
import net.i2p.data.i2np.DatabaseSearchReplyMessage; import net.i2p.data.i2np.DatabaseSearchReplyMessage;
@ -17,7 +19,7 @@ import net.i2p.util.Log;
class SearchMessageSelector implements MessageSelector { class SearchMessageSelector implements MessageSelector {
private final Log _log; private final Log _log;
private final RouterContext _context; private final RouterContext _context;
private static int __searchSelectorId = 0; private static final AtomicInteger __searchSelectorId = new AtomicInteger();
private final Hash _peer; private final Hash _peer;
private boolean _found; private boolean _found;
private final int _id; private final int _id;
@ -31,7 +33,7 @@ class SearchMessageSelector implements MessageSelector {
_found = false; _found = false;
_exp = expiration; _exp = expiration;
_state = state; _state = state;
_id = ++__searchSelectorId; _id = __searchSelectorId.incrementAndGet();
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("[" + _id + "] Created: " + toString()); _log.debug("[" + _id + "] Created: " + toString());
} }

View File

@ -14,6 +14,7 @@ import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import net.i2p.I2PAppContext; import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper; import net.i2p.data.DataHelper;
@ -902,7 +903,7 @@ class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
return "?"; return "?";
} }
private static int __id = 0; private static final AtomicInteger __id = new AtomicInteger();
/** /**
* postControlAction() can take many seconds, especially if it's failing, * postControlAction() can take many seconds, especially if it's failing,
@ -925,7 +926,7 @@ class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
_log.info("Starting thread to forward " + portsToForwardNow.size() + " ports"); _log.info("Starting thread to forward " + portsToForwardNow.size() + " ports");
Thread t = new Thread(new RegisterPortsThread(portsToForwardNow)); Thread t = new Thread(new RegisterPortsThread(portsToForwardNow));
t.setName("UPnP Port Opener " + (++__id)); t.setName("UPnP Port Opener " + __id.incrementAndGet());
t.setDaemon(true); t.setDaemon(true);
t.start(); t.start();
} }
@ -967,7 +968,7 @@ class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
_log.info("Starting thread to un-forward " + portsToForwardNow.size() + " ports"); _log.info("Starting thread to un-forward " + portsToForwardNow.size() + " ports");
Thread t = new Thread(new UnregisterPortsThread(portsToForwardNow)); Thread t = new Thread(new UnregisterPortsThread(portsToForwardNow));
t.setName("UPnP Port Closer " + (++__id)); t.setName("UPnP Port Closer " + __id.incrementAndGet());
t.setDaemon(true); t.setDaemon(true);
t.start(); t.start();
} }