當前位置: 首頁>>代碼示例>>Java>>正文


Java ListeningExecutorService.submit方法代碼示例

本文整理匯總了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();
}
 
開發者ID:hartwigmedical,項目名稱:hmftools,代碼行數:30,代碼來源:FastqStats.java

示例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);
}
 
開發者ID:thingsboard,項目名稱:thingsboard,代碼行數:18,代碼來源:JpaDeviceDaoTest.java

示例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;
}
 
開發者ID:LiaisonTechnologies,項目名稱:shachi,代碼行數:23,代碼來源:HBaseControl.java

示例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);
}
 
開發者ID:glowroot,項目名稱:glowroot,代碼行數:22,代碼來源:GuavaListenableFutureIT.java

示例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");
	}
 
開發者ID:dswarm,項目名稱:dswarm-graph-neo4j,代碼行數:18,代碼來源:GDMResource.java

示例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();
            }
        }
    });
}
 
開發者ID:naver,項目名稱:pinpoint,代碼行數:17,代碼來源:ActiveTraceRepositoryTest.java

示例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();
    });
}
 
開發者ID:MineboxOS,項目名稱:minebox,代碼行數:9,代碼來源:LazyEncyptionKeyProvider.java

示例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));
	}
}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:14,代碼來源:ListenableFutureDemo.java

示例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;
}
 
開發者ID:coinblesk,項目名稱:coinblesk-client-gui,代碼行數:33,代碼來源:WalletService.java

示例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;
}
 
開發者ID:xsingHu,項目名稱:xs-android-architecture,代碼行數:12,代碼來源:GithubApiProducerModule.java

示例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);
      });
}
 
開發者ID:bazelbuild,項目名稱:intellij,代碼行數:16,代碼來源:GitBlazeVcsHandler.java

示例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));
}
 
開發者ID:bazelbuild,項目名稱:intellij,代碼行數:10,代碼來源:GitBlazeVcsHandler.java

示例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);
}
 
開發者ID:google,項目名稱:binnavi,代碼行數:15,代碼來源:CGraphOpener.java

示例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());
}
 
開發者ID:fxnn,項目名稱:brainfuck-on-genetics,代碼行數:13,代碼來源:BrainfuckOnGeneticsJob.java

示例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);
        }
      });
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:10,代碼來源:ChangeRebuilder.java


注:本文中的com.google.common.util.concurrent.ListeningExecutorService.submit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。