chapter_004_Multithreading/src/main/java/nonblockingalgoritm/CacheForModel.java
public void update(Model updateValue) {

        storage.computeIfPresent(updateValue.hashCode(), new BiFunction<Integer, Model, Model>() {
            @Override
            public Model apply(Integer integer, Model valueInStorage) {
                if (updateValue.getVersion() != valueInStorage.getVersion()) {
                    try {
                        throw new OptimisticException("Error collision! Model update other thread");
                    } catch (OptimisticException e) {
                        e.printStackTrace();
                    }
                }
                updateValue.incrementVersion();
                System.out.println(updateValue);
                return updateValue;
            }
        });
    }
/**
     * Update value.
     *
     * @param updateValue Model
     */
Update value.
@param updateValue Model
Update value . @param updateValue Model
public void update(Model updateValue) {
        storage.computeIfPresent(updateValue.hashCode(), new BiFunction<Integer, Model, Model>() {
            @Override
            public Model apply(Integer integer, Model valueInStorage) {
                if (updateValue.getVersion() != valueInStorage.getVersion()) {
                    try {
                        throw new OptimisticException("Error collision! Model update other thread");
                    } catch (OptimisticException e) {
                        e.printStackTrace();
                    }
                }
                updateValue.incrementVersion();
                System.out.println(updateValue);
                return updateValue;
            }
        });
    }
public void update ( Model updateValue ) { storage . computeIfPresent ( updateValue . hashCode ( ) , new BiFunction < Integer , Model , Model > ( ) { @ Override public Model apply ( Integer integer , Model valueInStorage ) { if ( updateValue . getVersion ( ) != valueInStorage . getVersion ( ) ) { try { throw new OptimisticException ( "Error collision! Model update other thread" ) ; } catch ( OptimisticException e ) { e . printStackTrace ( ) ; } } updateValue . incrementVersion ( ) ; System . out . println ( updateValue ) ; return updateValue ; } } ) ; }
Update value.
Update value .