com.alexkasko.springjdbc.parallel.ExceptionHolder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of parallel-queries Show documentation
Show all versions of parallel-queries Show documentation
Processes given SQL query in parallel in multiple data sources (assuming that all data source
contain the same data). Combined results from multiple queries are exposed to application as
java.util.Iterator. Worker thread use spring's JdbcTemplate with named parameters support.
package com.alexkasko.springjdbc.parallel;
import java.util.concurrent.atomic.AtomicReference;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Worker exception holder, holds only first setted value, ignores subsequent values.
* Throws stored exception on demand.
* Thread-safe.
*
* @author alexkasko
* Date: 6/12/12
*/
class ExceptionHolder {
private AtomicReference target = new AtomicReference();
/**
* Returns stored exception or null
*
* @return stored exception or null
*/
RuntimeException get() {
return target.get();
}
/**
* @param target value to set, ignored if value was already set
*/
void set(RuntimeException target) {
checkNotNull(target, "Holded value must be non null");
this.target.compareAndSet(null, target);
}
}