本文整理匯總了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);
}
});
}