Author: zothar
Date: 2006-07-10 00:10:10 +0000 (Mon, 10 Jul 2006)
New Revision: 9536
Modified:
trunk/freenet/src/freenet/io/NetworkInterface.java
Log:
lint4j says calling native methods while holding a lock is bad because native
methods incur an expensive context switch. Since that sounds reasonable to me,
I've experimented with the first such condition it listed and this is the
result. I'm not completely sure I understand the complete implications of the
lock here, so feel free to revert if I did something stupid.
Modified: trunk/freenet/src/freenet/io/NetworkInterface.java
===================================================================
--- trunk/freenet/src/freenet/io/NetworkInterface.java 2006-07-09 23:55:29 UTC
(rev 9535)
+++ trunk/freenet/src/freenet/io/NetworkInterface.java 2006-07-10 00:10:10 UTC
(rev 9536)
@@ -24,11 +24,13 @@
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
+import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
+import java.util.Vector;
import freenet.io.AddressIdentifier.AddressType;
import freenet.support.Logger;
@@ -156,6 +158,7 @@
* if the timeout has expired waiting for a connection
*/
public Socket accept() throws SocketTimeoutException {
+ Vector tempThreads = new Vector();
synchronized (syncObject) {
if (!started) {
started = true;
@@ -163,9 +166,14 @@
while (acceptors.hasNext()) {
Thread t = new Thread((Acceptor)
acceptors.next(), "Network Interface Acceptor");
t.setDaemon(true);
- t.start();
+ tempThreads.add(t);
}
}
+ }
+ for(Enumeration e = tempThreads.elements();
e.hasMoreElements(); ) {
+ ((Thread) e.nextElement()).start();
+ }
+ synchronized (syncObject) {
while (acceptedSockets.size() == 0) {
try {
syncObject.wait(timeout);