Socket client;
Socket clientSocket;
    public void run() {        long beforeTime = 0;        long afterTime = 0;        Socket client;        int hitPosition = 0;        int total = 0;        int x = 0;        int sizeHitList = lastHits.length;        boolean firstDataValue = true;        String newHost = "";        Vector newHosts = null;        while (!terminated) {            try {                // sleep until a proper timeout                // changes in times result in new sleep                sleeping = true;                while (sleeping) {                    try {                        if (this.frequency < maxValue) {                            int targetSleep = (this.frequency * factor);                            logger.log(name,                                "freq " + frequency + " factor " + factor);                            if (targetSleep <= 0) {                                timeSleep = 0;                            } else {                                int rnd = random.nextInt(targetSleep);                                logger.log(name,                                    "sleep numbers are " + rnd + " " +                                    targetSleep + " " + afterTime + " " +                                    beforeTime);                                timeSleep = (rnd + (targetSleep / 2)) -                                    (int) (afterTime - beforeTime);                                if (timeSleep < 0) {                                    timeSleep = 0;                                } else if (timeSleep > (2 * targetSleep)) {                                    logger.log(name,                                        "emergency correction - attempted sleep " +                                        timeSleep);                                    timeSleep = targetSleep;                                }                            }                        } else {                            timeSleep = (1000 * 60 * 20);                        }                        logger.log(name, "sleeping for " + timeSleep);                        if ((timeSleep) > 0) {                            Thread.sleep(timeSleep);                        }                        sleeping = false;                        logger.log(name, "awake again...");                    } catch (InterruptedException ie) {                        logger.err(name,                            "interrupted sleep - returning to sleep ," +                            ie.getMessage());                    } catch (Exception ex) {                        logger.err(name,                            "Setting time to sleep: " + ex.getMessage());                    }                }                newHosts = getHosts();                boolean succeeded = false;                while (!terminated && !succeeded && (newHosts.size() > 0)) {                    // try them all in random order until one works...                    int hostId = random.nextInt(newHosts.size());                    // should be 0 to size-1                    newHost = (String) newHosts.elementAt(hostId);                    newHosts.removeElementAt(hostId);                    logger.log(name, "trying server " + newHost);                    beforeTime = System.currentTimeMillis();                    client = connect(newHost, this.port);                    if (client != null) {                        logger.log(name, "connected to server " + newHost);                        succeeded = true;                        afterTime = handleConnection(newHost, client);                        if (afterTime >= beforeTime) {                            int newTime = ((int) (afterTime - beforeTime));                            if (firstDataValue) {                                firstDataValue = false;                                for (x = 0; x < sizeHitList; x++) {                                    lastHits[x] = newTime;                                }                            }                            if (newTime == 0) {                                break;                            }                            lastHits[hitPosition] = newTime;                            total = 0;                            for (x = 0; x < sizeHitList; x++) {                                total = total + lastHits[x];                            }                            this.data = total / sizeHitList;                            hitPosition++;                            if (hitPosition >= sizeHitList) {                                hitPosition = 0;                            }                        } else {                            logger.log(name,                                "potential problem coming up - after is early than before!");                        }                        logger.log(name,                            "> Access to Host: " + newHost + ":" + port + ", " +                            this.requestLine + ", " + ", elapseTime" + ":" +                            this.data + ", toSleep:" + timeSleep);                    }                }            } catch (Throwable ex) {                logger.log(name,                    "In while(!terminated) loop: " + newHost + ", " +                    ex.getMessage());            }        }    }