Example usage for org.springframework.batch.core.scope.context StepContext setAttribute

List of usage examples for org.springframework.batch.core.scope.context StepContext setAttribute

Introduction

In this page you can find the example usage for org.springframework.batch.core.scope.context StepContext setAttribute.

Prototype

@Override
    public void setAttribute(String name, Object value) 

Source Link

Usage

From source file:org.springframework.batch.core.scope.StepScope.java

/**
 * @see Scope#get(String, ObjectFactory)
 *//*from   w  ww . j a  va 2 s  .c om*/
@Override
public Object get(String name, ObjectFactory<?> objectFactory) {
    StepContext context = getContext();
    Object scopedObject = context.getAttribute(name);

    if (scopedObject == null) {

        synchronized (mutex) {
            scopedObject = context.getAttribute(name);
            if (scopedObject == null) {

                if (logger.isDebugEnabled()) {
                    logger.debug(String.format("Creating object in scope=%s, name=%s", this.getName(), name));
                }

                scopedObject = objectFactory.getObject();
                context.setAttribute(name, scopedObject);

            }

        }

    }
    return scopedObject;
}