diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java index 5d9066003..8ebb54785 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java @@ -57,6 +57,9 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna private String handlerName; + private Object conLock = new Object(); + private int pendingConnections = 0; + //public I2PTunnelClientBase(int localPort, boolean ownDest, // Logging l) { // I2PTunnelClientBase(localPort, ownDest, l, (EventDispatcher)null); @@ -269,7 +272,16 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna * @param s Socket to take care of */ protected void manageConnection(Socket s) { - new ClientConnectionRunner(s, handlerName); + boolean useBlocking = false; + synchronized (conLock) { + pendingConnections++; + if (pendingConnections > 5) + useBlocking = true; + } + if (useBlocking) + clientConnectionRun(s); + else + new ClientConnectionRunner(s, handlerName); } public boolean close(boolean forced) { @@ -326,6 +338,9 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna public void run() { clientConnectionRun(s); + synchronized (conLock) { + pendingConnections--; + } } } diff --git a/core/java/src/net/i2p/data/DataHelper.java b/core/java/src/net/i2p/data/DataHelper.java index b4ce9a196..6a32f57a3 100644 --- a/core/java/src/net/i2p/data/DataHelper.java +++ b/core/java/src/net/i2p/data/DataHelper.java @@ -34,6 +34,7 @@ import java.util.TreeMap; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; +import net.i2p.util.ByteCache; import net.i2p.util.OrderedProperties; /** @@ -737,13 +738,16 @@ public class DataHelper { if ((orig == null) || (orig.length <= 0)) return orig; GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(orig, offset, length), length); ByteArrayOutputStream baos = new ByteArrayOutputStream(length * 2); - byte buf[] = new byte[4 * 1024]; + ByteCache cache = ByteCache.getInstance(10, 4*1024); + ByteArray ba = cache.acquire(); + byte buf[] = ba.getData(); // new byte[4 * 1024]; while (true) { int read = in.read(buf); if (read == -1) break; baos.write(buf, 0, read); } byte rv[] = baos.toByteArray(); + cache.release(ba); //if (_log.shouldLog(Log.DEBUG)) // _log.debug("Decompression of " + orig.length + " into " + rv.length + " (or " + 100.0d // * (((double) rv.length) / ((double) orig.length)) + "% savings)");