
org.bbottema.clusteredobjectpool.util.CompositeFuturesAsFutureTask Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of clustered-object-pool Show documentation
Show all versions of clustered-object-pool Show documentation
Clustered and keyed generic object pools
The newest version!
/*
* Copyright © 2019 Benny Bottema ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.bbottema.clusteredobjectpool.util;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import static java.util.concurrent.Executors.defaultThreadFactory;
import static java.util.concurrent.Executors.newSingleThreadExecutor;
public class CompositeFuturesAsFutureTask extends FutureTask {
public static Future ofFutures(final List> futures) {
ExecutorService executorService = newSingleThreadExecutor(defaultThreadFactory());
Future future = executorService.submit(new CompositeFuturesAsFutureTask(futures), null);
executorService.shutdown();
return future;
}
private CompositeFuturesAsFutureTask(final List> futures) {
super(new Callable() {
@Override
public Void call() throws ExecutionException, InterruptedException {
for (Future future : futures) {
future.get();
}
return null;
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy