public synchronized Pair getDataFromFrontOfQueue(DomainLock domainLock){
        Data data = queueHandle.getNextData();
        boolean yourLock = false;
        //if lock for table does not exists or if it is false lock the table
        if(!domainLock.isLocked(data.getDomain())){
            domainLock.acquireLock(data.getDomain());
            yourLock = true;
        }
        Pair p = new Pair();
        p.data = data;
        p.yourLock = yourLock;
        return p;
    }
Given a queue which gets millions of messages. Message is of form <Domain,Update>.
You have 10000 domain tables. Also you have 50 worker threads. You can only get 
data from front of the queue. Threads get data from the front and then update the 
domain table. If work is being done on domain table you cannot apply another update.
Update should also be applied sequentially. So an update coming later on should not
be applied before an update coming sooner.
src/com/interview/multithreaded/SingleQueueDomainTableUpdate.java