public void run() {
            log("Worker thread up");
            while(true){
                lock.lock();
                Token token = null;
                try {
                    token = workQueue.remove();
                    working++;
                }catch(NoSuchElementException e){
                    token = null;
                }
                lock.unlock();
                if (token != null) {
                    log("Starting work: " + Integer.toString(token.getId()));
                    LRState state = token.getState();
                    log("Starting folding: " + Integer.toString(token.getId()));
                    int i = 0;
                    for (Double[] rec : data) {
                        state = folder.fold(state, rec);
                        i++;
                    }
                    Token outToken = token.setState(state);
                    try {
                        uploadToken(outToken);
                    } catch (RemoteException e) {
                        e.printStackTrace();
                    } finally {
                        lock.lock();
                        working--;
                        lock.unlock();
                    }
                    for(ControllerInterface controller:controllers){
                        try {
                            controller.doneWithWork(workerId, token.getId(), token.getVersion());
                            break;
                        }catch(RemoteException e){
                            log(e.getMessage());
                        }
                    }
                }
            }
        }