It's sensible, but try to avoid allocations if you can; can you put the
thread onto the acceptor, and avoid the extra list?

On Mon, Jul 10, 2006 at 12:10:13AM +0000, zothar at freenetproject.org wrote:
> 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);
> 
> _______________________________________________
> cvs mailing list
> cvs at freenetproject.org
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
> 

-- 
Matthew J Toseland - toad at amphibian.dyndns.org
Freenet Project Official Codemonkey - http://freenetproject.org/
ICTHUS - Nothing is impossible. Our Boss says so.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: 
<https://emu.freenetproject.org/pipermail/cvs/attachments/20060711/6db62937/attachment.pgp>

Reply via email to