Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] HttpClient - concurrency improvement

HttpClient.getDestination would realize a significant concurrency improvement (avoiding a synchronized block) by using java.util.concurrent.ConcurrentHashMap; this assumes Java 5+.

 

    private Map<Address, HttpDestination> destinations = new ConcurrentHashMap<Address, HttpDestination>();

   

 

    public HttpDestination getDestination( Address address, boolean ssl ) throws UnknownHostException, IOException

    {

        HttpDestination destination = destinations.get( address );

        if( destination == null )

        {

            // not found in the map; lock to ensure a stable view

            synchronized( destinations )

            {

                destination = destinations.get( address );

                if( destination == null )

                {

                    destination = super.getDestination( address, ssl );

                    destinations.put( address, destination );

                }

            }

        }

        assert destination != null;

        return destination;

    }

 

 


Back to the top