RemoteURL target = null;
VerifyURL vu = null;
    public void urlVerifier(ServletContext context) {        for (;;) {            RemoteURL target = null;            /*             * Wait until there is anything to verify.             */            synchronized (verifyList) {                while (verifyList.isEmpty()) {                    try {                        verifyList.wait();                    } catch (InterruptedException ex) {                        //context.log("urlVerifier exiting");                        return;                    }                }                target = (RemoteURL)verifyList.removeFirst();            }            /*             * In case we did not wait check if the thread is supposed             * to exit.             */            if (Thread.interrupted())                return;            target.setCacheVersion(RemoteURL.STATE_CHECKING);            try {                String testURL = target.getRemoteURL();                int protoVersion = target.getProtoVersion();                if (protoVersion == RemoteURL.PROTO_V1)                    testURL = testURL + "?ping=1";                else {                    /*                     * Well, the get=1 parameter forces a V2 query. It                     * would be nice if all scripts did understand the                     * Jon Atkins extension ping=2.                     */                    testURL = testURL + "?ping=1&get=1";                    /*                     * Special hack for the bazooka php script - it insists                     * on net=gnutella2 in a ping request. Fake this here                     * although I think it is not correct to require a                     * particular network on a ping.                     */                    if (testURL.indexOf("bazooka") != -1)                        testURL = testURL + "&net=gnutella2";                }                testURL = testURL + "&client=JGWC&version=" + GWebCache.getVersion();                //context.log("verifying: " + testURL);                URL url = new URL(testURL);                HttpURLConnection urlConn = (HttpURLConnection)url.openConnection();                /*                 * Avoid redirects as these point to error pages in most                 * of the cases anyways.                 */                urlConn.setInstanceFollowRedirects(false);                BufferedReader in = new BufferedReader(new InputStreamReader(                                                urlConn.getInputStream()));                if (urlConn.getResponseCode() != HttpURLConnection.HTTP_OK)                    throw new BadResponseException(urlConn.getResponseCode(),                                                urlConn.getResponseMessage());                String line;                String firstLine = null;                String cacheVersion = null;                while ((line = in.readLine()) != null) {                    if (Thread.interrupted())                        return;                    if (firstLine == null && line.trim().length() > 0)                        firstLine = line;                    if (protoVersion == RemoteURL.PROTO_V1) {                        if (line.length() > 4 &&                             line.substring(0, 4).equalsIgnoreCase("PONG")) {                            cacheVersion = line.substring(4);                            break;                        }                    } else {                        if (line.length() > 7 &&                             line.substring(0, 7).equalsIgnoreCase("I|pong|")) {                            cacheVersion = line.substring(7);                            int i = cacheVersion.indexOf('|');                            if (i != -1)                                cacheVersion = cacheVersion.substring(0, i);                            break;                        }                        /*                         * We expect a V2 pong here, but also accept the V1                         * style that some caches use.                         */                        if (line.length() > 4 &&                             line.substring(0, 4).equalsIgnoreCase("PONG")) {                            cacheVersion = "V1:" + line.substring(4);                            break;                        }                    }                }                in.close();                if (cacheVersion == null) {                    if (firstLine == null)                        firstLine = "empty response";                    /*                     * Do some quick and dirty HTML escaping on the                     * received text.                     */                    firstLine = firstLine.replaceAll("&", "&amp;");                    firstLine = firstLine.replaceAll("<", "&lt;");                    firstLine = firstLine.replaceAll(">", "&gt;");                    cacheVersion = RemoteURL.STATE_FAILED + ": " + firstLine;                }                target.setCacheVersion(cacheVersion.trim());            } catch (Exception ex) {                //context.log("verify exception:", ex);                target.setCacheVersion(RemoteURL.STATE_FAILED + ": " + ex);            }        }    }