use of com.google.common.util.concurrent.ListeningExecutorService in project jackrabbit-oak by apache.
the class ConcurrentReadIT method concurrentNodeIteration.
@Test
public void concurrentNodeIteration() throws RepositoryException, InterruptedException, ExecutionException {
final Session session = createAdminSession();
try {
final Node testRoot = session.getRootNode().addNode("test-root");
for (int k = 0; k < 50; k++) {
testRoot.addNode("n" + k);
}
session.save();
ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
List<ListenableFuture<?>> futures = Lists.newArrayList();
for (int k = 0; k < 20; k++) {
futures.add(executorService.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
for (int k = 0; k < 10000; k++) {
session.refresh(false);
NodeIterator children = testRoot.getNodes();
children.hasNext();
}
return null;
}
}));
}
// Throws ExecutionException if any of the submitted task failed
Futures.allAsList(futures).get();
executorService.shutdown();
executorService.awaitTermination(1, TimeUnit.DAYS);
} finally {
session.logout();
}
}
use of com.google.common.util.concurrent.ListeningExecutorService in project bazel by bazelbuild.
the class JarFilter method parseJavaFiles.
/** Finds the expected jar archive file name prefixes for the java files. */
static List<String> parseJavaFiles(List<Path> javaFiles) throws IOException {
ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()));
List<ListenableFuture<String>> futures = Lists.newArrayList();
for (final Path javaFile : javaFiles) {
futures.add(executorService.submit(new Callable<String>() {
@Override
public String call() throws Exception {
String packageString = getDeclaredPackageOfJavaFile(javaFile);
return packageString != null ? getArchiveFileNamePrefix(javaFile.toString(), packageString) : null;
}
}));
}
try {
List<String> archiveFileNamePrefixes = Futures.allAsList(futures).get();
List<String> result = Lists.newArrayList();
for (String archiveFileNamePrefix : archiveFileNamePrefixes) {
if (archiveFileNamePrefix != null) {
result.add(archiveFileNamePrefix);
}
}
return result;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException(e);
} catch (ExecutionException e) {
throw new IOException(e);
}
}
use of com.google.common.util.concurrent.ListeningExecutorService in project bazel by bazelbuild.
the class PackageParser method parsePackageStrings.
@Nonnull
@VisibleForTesting
public Map<ArtifactLocation, String> parsePackageStrings(@Nonnull List<ArtifactLocation> sources) throws Exception {
ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()));
Map<ArtifactLocation, ListenableFuture<String>> futures = Maps.newHashMap();
for (final ArtifactLocation source : sources) {
futures.put(source, executorService.submit(new Callable<String>() {
@Override
public String call() throws Exception {
return getDeclaredPackageOfJavaFile(source);
}
}));
}
Map<ArtifactLocation, String> map = Maps.newHashMap();
for (Entry<ArtifactLocation, ListenableFuture<String>> entry : futures.entrySet()) {
String value = entry.getValue().get();
if (value != null) {
map.put(entry.getKey(), value);
}
}
return map;
}
use of com.google.common.util.concurrent.ListeningExecutorService in project zipkin by openzipkin.
the class DeduplicatingExecutorTest method exceptionArentCached_deferredFuture.
@Test
public void exceptionArentCached_deferredFuture() throws Exception {
ListeningExecutorService exec = listeningDecorator(Executors.newSingleThreadExecutor());
try {
executor = TestDeduplicatingExecutor.create(s -> {
if (s == first) {
return exec.submit(() -> {
Thread.sleep(50);
throw new IllegalArgumentException();
});
}
return Futures.immediateFuture(s);
});
exceptionsArentCached();
} finally {
exec.shutdownNow();
}
}
use of com.google.common.util.concurrent.ListeningExecutorService in project bazel by bazelbuild.
the class AndroidResourceProcessor method deserializeSymbolsToData.
/** Deserializes a list of serialized resource paths to a {@link ParsedAndroidData}. */
public ParsedAndroidData deserializeSymbolsToData(List<Path> symbolPaths) throws IOException, MergingException {
AndroidDataDeserializer deserializer = AndroidDataDeserializer.create();
final ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(15));
final Builder deserializedDataBuilder = ParsedAndroidData.Builder.newBuilder();
try (Closeable closeable = ExecutorServiceCloser.createWith(executorService)) {
List<ListenableFuture<Boolean>> deserializing = new ArrayList<>();
for (final Path symbolPath : symbolPaths) {
deserializing.add(executorService.submit(new Deserialize(deserializer, symbolPath, deserializedDataBuilder)));
}
FailedFutureAggregator<MergingException> aggregator = FailedFutureAggregator.createForMergingExceptionWithMessage("Failure(s) during dependency parsing");
aggregator.aggregateAndMaybeThrow(deserializing);
}
return deserializedDataBuilder.build();
}
Aggregations