Package org.htmlunit

Class WebClient.CSS3ParserPool

  • Enclosing class:
    WebClient

    static class WebClient.CSS3ParserPool
    extends java.lang.Object
    Our pool of CSS3Parsers. If you need a parser, get it from here and use the AutoCloseable functionality with a try-with-resource block. If you don't want to do that at all, continue to build CSS3Parsers the old fashioned way. Fetching a parser is thread safe. This API is built to minimize synchronization overhead, hence it is possible to miss a returned parser from another thread under heavy pressure, but because that is unlikely, we keep it simple and efficient. Caches are not supposed to give cutting-edge guarantees. This concept avoids a resource leak when someone does not close the fetched parser because the pool does not know anything about the parser unless it returns. We are not running a checkout-checkin concept. INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
    • Constructor Detail

      • CSS3ParserPool

        CSS3ParserPool()
    • Method Detail

      • get

        public WebClient.PooledCSS3Parser get()
        Fetch a new or recycled CSS3parser. Make sure you use the try-with-resource concept to automatically return it after use because a parser creation is expensive. We won't get a leak, if you don't do so, but that will remove the advantage.
        Returns:
        a parser
      • recycle

        protected void recycle​(WebClient.PooledCSS3Parser parser)
        Return a parser. Normally you don't have to use that method explicitly. Prefer to user the AutoCloseable interface of the PooledParser by using a try-with-resource statement.
        Parameters:
        parser - the parser to recycle