DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4418>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4418

Race Condition in net.serversocketfactory.java





------- Additional Comments From [EMAIL PROTECTED]  2001-10-25 06:56 -------
    public static ServerSocketFactory getDefault () {
        //
        // optimize typical case:  no synch needed
        //

        if (theFactory == null) {
            synchronized (ServerSocketFactory.class) {
                //
                // Different implementations of this method could
                // work rather differently.  For example, driving
                // this from a system property, or using a different
                // implementation than JavaSoft's.
                //

                theFactory = new DefaultServerSocketFactory ();
            }
        }

this code is incorrect, as two threads could perform the check and create a new 
DefaultServerSocketFactory.  Change the code to something like

    public static ServerSocketFactory getDefault () {
        //
        // optimize typical case:  no synch needed
        //

        if (theFactory == null) {
            synchronized (ServerSocketFactory.class) {
                //
                // Different implementations of this method could
                // work rather differently.  For example, driving
                // this from a system property, or using a different
                // implementation than JavaSoft's.
                //

                //***** Prevent two threads from doing this after unsychronized 
check!
                if (theFactory == NULL)
                theFactory = new DefaultServerSocketFactory ();
            }
        }

Reply via email to