本文整理汇总了Java中com.google.common.util.concurrent.ListeningExecutorService.submit方法的典型用法代码示例。如果您正苦于以下问题:Java ListeningExecutorService.submit方法的具体用法?Java ListeningExecutorService.submit怎么用?Java ListeningExecutorService.submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.util.concurrent.ListeningExecutorService
的用法示例。
在下文中一共展示了ListeningExecutorService.submit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processFastqs
import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
/**
* Counts yield and q30 of fastqs in the fastqsPerSample multimap, using 1 thread per file.
* The yield and q30 of the Undetermined sample will count towards the total yield and q30 of the flowcell.
*
* @param fastqsPerSample multimap of sampleName and fastqs to process
* @param threadCount number of maximum threads
* @return FastqTracker with yield and q30 stats for the fastqs processed.
*/
@NotNull
static FastqTracker processFastqs(@NotNull final Multimap<String, File> fastqsPerSample, final int threadCount)
throws InterruptedException {
LOGGER.info("Using " + threadCount + " threads. Processing " + fastqsPerSample.size() + " fastQ files.");
final FastqTrackerWrapper tracker = new FastqTrackerWrapper();
final ListeningExecutorService threadPool = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(threadCount));
for (final String sampleName : fastqsPerSample.keySet()) {
final Collection<File> fastqs = fastqsPerSample.get(sampleName);
for (final File fastq : fastqs) {
final String laneName = getLaneName(fastq);
final ListenableFuture<FastqData> futureResult = threadPool.submit(() -> processFile(fastq));
addCallback(futureResult, (data) -> tracker.addDataFromSampleFile(sampleName, laneName, data),
(error) -> LOGGER.error("Failed to process file: " + fastq.getName(), error));
}
}
threadPool.shutdown();
threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
return tracker.tracker();
}
示例2: testFindAsync
import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
@Test
public void testFindAsync() throws ExecutionException, InterruptedException {
UUID tenantId = UUIDs.timeBased();
UUID customerId = UUIDs.timeBased();
Device device = getDevice(tenantId, customerId);
deviceDao.save(device);
UUID uuid = device.getId().getId();
Device entity = deviceDao.findById(uuid);
assertNotNull(entity);
assertEquals(uuid, entity.getId().getId());
ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10));
ListenableFuture<Device> future = service.submit(() -> deviceDao.findById(uuid));
Device asyncDevice = future.get();
assertNotNull("Async device expected to be not null", asyncDevice);
}
示例3: execAsync
import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
/**
* Tunnelling method so that OperationController with access to the delegate can use the
* execution thread pool established in the HBaseControl.
* @param operationExecutable
* @return
* @throws UnsupportedOperationException
*/
public ListenableFuture<OpResultSet> execAsync(Callable<OpResultSet> operationExecutable) throws UnsupportedOperationException {
String logMsg;
final ListeningExecutorService asyncPool;
final ListenableFuture<OpResultSet> execTask;
asyncPool = HBaseControl.this.execPool;
if (asyncPool == null) {
logMsg = HBaseControl.class.getSimpleName()
+ " (context.id='"
+ HBaseControl.this.context.getId()
+ "') does not support asynchronous operations";
throw new UnsupportedOperationException(logMsg);
}
execTask = asyncPool.submit(operationExecutable);
return execTask;
}
示例4: transactionMarker
import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
@Override
public void transactionMarker() throws Exception {
ListeningExecutorService executor =
MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
ListenableFuture<Void> future1 = executor.submit(new Callable<Void>() {
@Override
public Void call() throws InterruptedException {
Thread.sleep(100);
return null;
}
});
future1.addListener(new Runnable() {
@Override
public void run() {
new CreateTraceEntry().traceEntryMarker();
}
}, executor);
Thread.sleep(200);
executor.shutdown();
executor.awaitTermination(10, SECONDS);
}
示例5: shutDownDeltaDBs
import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
private void shutDownDeltaDBs(final GraphDatabaseService existingResourceDB, final GraphDatabaseService newResourceDB) {
GDMResource.LOG.debug("start shutting down working graph data model DBs for resources");
// should probably be delegated to a background worker thread, since it looks like that shutting down the working graph
// DBs take some time (for whatever reason)
final ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10));
service.submit((Callable<Void>) () -> {
newResourceDB.shutdown();
existingResourceDB.shutdown();
return null;
});
GDMResource.LOG.debug("finished shutting down working graph data model DBs for resources");
}
示例6: executeSampledContinuedTrace
import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
private ListenableFuture<TraceThreadTuple> executeSampledContinuedTrace(ListeningExecutorService executorService, final CountDownLatch awaitLatch, final CountDownLatch executeLatch, final long id) {
return executorService.submit(new Callable<TraceThreadTuple>() {
@Override
public TraceThreadTuple call() throws Exception {
try {
TraceId agentId1 = new DefaultTraceId("agentId", 0L, id);
Trace agentId = traceContext.continueTraceObject(agentId1);
return new TraceThreadTuple(agentId, Thread.currentThread().getId());
} finally {
executeLatch.countDown();
awaitLatch.await();
traceContext.removeTraceObject();
}
}
});
}
示例7: buildFuturePassword
import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
private ListenableFuture<String> buildFuturePassword(ListeningExecutorService executorService) {
return executorService.submit(() -> {
final String password1 = tryLoadingExistingFile();
if (password1 != null) return password1;
LOGGER.info("keyfile not found, watching for file creation...");
return waitForFileCreation();
});
}
示例8: testRateLimiter
import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
/**
* RateLimiter类似于JDK的信号量Semphore,他用来限制对资源并发访问的线程数
*/
public static void testRateLimiter() {
ListeningExecutorService executorService = MoreExecutors
.listeningDecorator(Executors.newCachedThreadPool());
RateLimiter limiter = RateLimiter.create(5.0); // 每秒不超过4个任务被提交
for (int i = 0; i < 10; i++) {
limiter.acquire(); // 请求RateLimiter, 超过permits会被阻塞
final ListenableFuture<Integer> listenableFuture = executorService
.submit(new Task("is " + i));
}
}
示例9: sendCoins
import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
public ListenableFuture<Transaction> sendCoins(final Address address, final Coin amount) {
ExecutorService executor = Executors.newSingleThreadExecutor(bitcoinjThreadFactory);
ListeningExecutorService sendCoinsExecutor = MoreExecutors.listeningDecorator(executor);
ListenableFuture<Transaction> txFuture = sendCoinsExecutor.submit(new Callable<Transaction>() {
@Override
public Transaction call() throws Exception {
BitcoinURI payment = new BitcoinURI(BitcoinURI.convertToBitcoinURI(address, amount, null, null));
CLTVInstantPaymentStep step = new CLTVInstantPaymentStep(walletServiceBinder, payment);
step.process(null);
Transaction fullySignedTx = step.getTransaction();
maybeCommitAndBroadcastTransaction(fullySignedTx);
Log.i(TAG, "Send Coins - address=" + address + ", amount=" + amount
+ ", txHash=" + fullySignedTx.getHashAsString());
return fullySignedTx;
}
});
sendCoinsExecutor.shutdown();
Futures.addCallback(txFuture, new FutureCallback<Transaction>() {
@Override
public void onSuccess(Transaction result) {
Log.i(TAG, "sendCoins - onSuccess - tx " + result.getHashAsString());
broadcastInstantPaymentSuccess();
}
@Override
public void onFailure(Throwable t) {
Log.e(TAG, "sendCoins - onFailure - failed with the following throwable: ", t);
broadcastInstantPaymentFailure();
}
});
return txFuture;
}
示例10: userModuleFactory
import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
public ListenableFuture<UserModule.Factory> userModuleFactory(final Application application){
ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
final ListenableFuture<UserModule.Factory> listenableFuture = executorService.submit(new Callable<UserModule.Factory>() {
@Override
public UserModule.Factory call() throws Exception {
UserModule.Factory userManager = produceUserModuleFactory(produceGithubApiService(application));
return userManager;
}
});
return listenableFuture;
}
示例11: getWorkingSet
import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
@Override
public ListenableFuture<WorkingSet> getWorkingSet(
Project project,
BlazeContext context,
WorkspaceRoot workspaceRoot,
ListeningExecutorService executor) {
return executor.submit(
() -> {
String upstreamSha = getUpstreamSha(workspaceRoot, false);
if (upstreamSha == null) {
return null;
}
return GitWorkingSetProvider.calculateWorkingSet(workspaceRoot, upstreamSha, context);
});
}
示例12: getUpstreamContent
import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
@Override
public ListenableFuture<String> getUpstreamContent(
Project project,
BlazeContext context,
WorkspaceRoot workspaceRoot,
WorkspacePath path,
ListeningExecutorService executor) {
return executor.submit(() -> getGitUpstreamContent(workspaceRoot, path));
}
示例13: showGraphAndPerformCallBack
import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
public static void showGraphAndPerformCallBack(final IViewContainer container,
final INaviView view, final CGraphWindow window, final Window parent,
final FutureCallback<Boolean> callBack) {
CWindowManager.instance().bringViewToFront(view);
final ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors
.newFixedThreadPool(10));
final ListenableFuture<Boolean> loader = service.submit(generateViewLoader(view, container,
window, parent));
Futures.addCallback(loader, callBack);
}
示例14: start
import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
public void start(BrainfuckOnGeneticsConfiguration configuration) throws JobCurrentlyRunningException {
if (isJobRunning()) {
throw new JobCurrentlyRunningException(timestampStarted);
}
ListeningExecutorService geneticAlgorithmExecutorService = configuration.getGeneticAlgorithmExecutorService();
GeneticAlgorithm<Program> geneticAlgorithm = algorithmFactory.createGeneticAlgorithm(configuration);
startClock();
future = geneticAlgorithmExecutorService.submit(geneticAlgorithm);
future.addListener(this::stopClock, MoreExecutors.directExecutor());
}
示例15: rebuildAsync
import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
public final ListenableFuture<Result> rebuildAsync(
Change.Id id, ListeningExecutorService executor) {
return executor.submit(
() -> {
try (ReviewDb db = schemaFactory.open()) {
return rebuild(db, id);
}
});
}