当前位置: 首页>>代码示例>>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;未经允许,请勿转载。