public void updateMinMax(int value){
        //update min
        while(true){
            //if value is greater than whatever is in min just break right away
            int minVal = min.get();
            if(value >= minVal){
                break;
            }
            //try to update value only if minVal is in min
            boolean isSetSuccesful = min.compareAndSet(minVal, value);
            //if set was successful break from while loop else keep looping
            if(isSetSuccesful){
                break;
            }
        }
        
        //update max
        while(true){
            int maxVal = max.get();
            if(value <= maxVal){
                break;
            }
            boolean isSetSuccesful = max.compareAndSet(maxVal, value);
            if(isSetSuccesful){
                break;
            }
        }
    }
Threadsafe way of updating min and max
@param value
src/com/interview/multithreaded/MinMaxKeeper.java