Example usage for org.springframework.batch.core.scope.context JobContext getAttribute

List of usage examples for org.springframework.batch.core.scope.context JobContext getAttribute

Introduction

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

Prototype

@Override
    public Object getAttribute(String name) 

Source Link

Usage

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

/**
 * @see Scope#get(String, ObjectFactory)
 *//*  w ww  .j a  v a2 s .  c  om*/
@Override
public Object get(String name, ObjectFactory<?> objectFactory) {
    JobContext 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;
}