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


Java Executor類代碼示例

本文整理匯總了Java中java.util.concurrent.Executor的典型用法代碼示例。如果您正苦於以下問題:Java Executor類的具體用法?Java Executor怎麽用?Java Executor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Executor類屬於java.util.concurrent包,在下文中一共展示了Executor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: Chats

import java.util.concurrent.Executor; //導入依賴的package包/類
@Inject
Chats(Executor messagePollThread, QuoteService service) {
    this.messagePollThread = messagePollThread;
    this.service = service;

    User alex = new User(0, "Alex");
    User chris = new User(1, "Chris");

    friends = asList(alex, chris);

    all = Collections.unmodifiableList(asList(//
            new Chat(this, 0, asList(alex, chris), //
                    asList(new Message(me, "What's up?"), //
                            new Message(alex, "Not much."), //
                            new Message(chris, "Wanna hang out?"), //
                            new Message(me, "Sure."), //
                            new Message(alex, "Let's do it.") //
                    )), //
            new Chat(this, 1, asList(chris), //
                    asList(new Message(me, "You there bro?") //
                    ))) //
    );
}
 
開發者ID:Zhuinden,項目名稱:simple-stack,代碼行數:24,代碼來源:Chats.java

示例2: addSubscriber

import java.util.concurrent.Executor; //導入依賴的package包/類
@Override
public <M, R> void addSubscriber(MessageSubject subject,
        Function<byte[], M> decoder,
        Function<M, R> handler,
        Function<R, byte[]> encoder,
        Executor executor) {
    checkPermission(CLUSTER_WRITE);
    messagingService.registerHandler(subject.value(),
            new InternalMessageResponder<M, R>(decoder, encoder, m -> {
                CompletableFuture<R> responseFuture = new CompletableFuture<>();
                executor.execute(() -> {
                    try {
                        responseFuture.complete(handler.apply(m));
                    } catch (Exception e) {
                        responseFuture.completeExceptionally(e);
                    }
                });
                return responseFuture;
            }));
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:21,代碼來源:ClusterCommunicationManager.java

示例3: continueWhile

import java.util.concurrent.Executor; //導入依賴的package包/類
/**
 * Continues a task with the equivalent of a Task-based while loop, where the body of the loop is
 * a task continuation.
 */
public Task<Void> continueWhile(final Callable<Boolean> predicate,
    final Continuation<Void, Task<Void>> continuation, final Executor executor,
    final CancellationToken ct) {
  final Capture<Continuation<Void, Task<Void>>> predicateContinuation =
      new Capture<>();
  predicateContinuation.set(new Continuation<Void, Task<Void>>() {
    @Override
    public Task<Void> then(Task<Void> task) throws Exception {
      if (ct != null && ct.isCancellationRequested()) {
        return Task.cancelled();
      }

      if (predicate.call()) {
        return Task.<Void> forResult(null).onSuccessTask(continuation, executor)
            .onSuccessTask(predicateContinuation.get(), executor);
      }
      return Task.forResult(null);
    }
  });
  return makeVoid().continueWithTask(predicateContinuation.get(), executor);
}
 
開發者ID:zuoweitan,項目名稱:Hitalk,代碼行數:26,代碼來源:Task.java

示例4: newExecutionList

import java.util.concurrent.Executor; //導入依賴的package包/類
@Override ExecutionListWrapper newExecutionList() {
  return new ExecutionListWrapper() {
    final ExecutionListCAS list = new ExecutionListCAS();
    @Override public void add(Runnable runnable, Executor executor) {
      list.add(runnable, executor);
    }

    @Override public void execute() {
      list.execute();
    }

    @Override public Object getImpl() {
      return list;
    }
  };
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:17,代碼來源:ExecutionListBenchmark.java

示例5: ClientNotifForwarder

import java.util.concurrent.Executor; //導入依賴的package包/類
public ClientNotifForwarder(ClassLoader defaultClassLoader, Map<String, ?> env) {
    maxNotifications = EnvHelp.getMaxFetchNotifNumber(env);
    timeout = EnvHelp.getFetchTimeout(env);

    /* You can supply an Executor in which the remote call to
       fetchNotifications will be made.  The Executor's execute
       method reschedules another task, so you must not use
       an Executor that executes tasks in the caller's thread.  */
    Executor ex = (Executor)
        env.get("jmx.remote.x.fetch.notifications.executor");
    if (ex == null)
        ex = new LinearExecutor();
    else if (logger.traceOn())
        logger.trace("ClientNotifForwarder", "executor is " + ex);

    this.defaultClassLoader = defaultClassLoader;
    this.executor = ex;
    this.acc = AccessController.getContext();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:ClientNotifForwarder.java

示例6: testWaitForFinalResult_whenOnlyIntermediateResult_thenNoUpdate

import java.util.concurrent.Executor; //導入依賴的package包/類
@Test
public void testWaitForFinalResult_whenOnlyIntermediateResult_thenNoUpdate() throws Throwable {
  when(mDataSource.isFinished()).thenReturn(false);
  when(mDataSource.getResult()).thenReturn(mIntermediateResult);

  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocation) throws Throwable {
      final Object[] args = invocation.getArguments();
      DataSubscriber dataSubscriber = (DataSubscriber) args[0];
      dataSubscriber.onNewResult(mDataSource);
      return null;
    }
  }).when(mDataSource).subscribe(any(DataSubscriber.class), any(Executor.class));

  // the mocked one falls through, but the real one waits with the countdown latch for isFinished
  final Object actual = DataSources.waitForFinalResult(mDataSource);
  assertEquals(null, actual);

  verify(mCountDownLatch, times(1)).await();
  verify(mCountDownLatch, never()).countDown();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:DataSourcesTest.java

示例7: doAbort

import java.util.concurrent.Executor; //導入依賴的package包/類
/**
 * Aborts all live connections, using the provided Executor.
 */
@Override
synchronized void doAbort(Executor executor) {
    // close all underlying connections
    for (MySQLConnection c : this.liveConnections.values()) {
        try {
            c.abort(executor);
        } catch (SQLException e) {
        }
    }

    if (!this.isClosed) {
        this.balancer.destroy();
        if (this.connectionGroup != null) {
            this.connectionGroup.closeConnectionProxy(this);
        }
    }

    this.liveConnections.clear();
    this.connectionsToHostsMap.clear();
}
 
開發者ID:rafallis,項目名稱:BibliotecaPS,代碼行數:24,代碼來源:LoadBalancedConnectionProxy.java

示例8: ScriptMonitor

import java.util.concurrent.Executor; //導入依賴的package包/類
public ScriptMonitor ( final String id, final String factoryId, final Executor executor, final BundleContext context, final Interner<String> stringInterner, final EventProcessor eventProcessor, final ObjectPoolTracker<DataSource> dataSourcePoolTracker, final ObjectPoolTracker<MasterItem> masterItemPoolTracker, final ServiceTracker<ConfigurationAdministrator, ConfigurationAdministrator> caTracker )
{
    super ( id, factoryId, executor, context, stringInterner, eventProcessor );
    this.executor = executor;

    this.prefix = stringInterner.intern ( factoryId + ". " + id ); //$NON-NLS-1$

    this.classLoader = getClass ().getClassLoader ();

    this.monitorStateInjector = new MonitorStateInjector ( stringInterner );
    this.monitorStateInjector.setPrefix ( this.prefix );

    this.handler = new InjectMasterHandler ( id, masterItemPoolTracker, 0, caTracker, this.prefix, factoryId );
    this.listener = new MultiDataSourceListener ( dataSourcePoolTracker ) {

        @Override
        protected void handleChange ( final Map<String, DataSourceHandler> sources )
        {
            ScriptMonitor.this.handleChange ( sources );
        }
    };
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:23,代碼來源:ScriptMonitor.java

示例9: newExecutionList

import java.util.concurrent.Executor; //導入依賴的package包/類
@Override ExecutionListWrapper newExecutionList() {
  return new ExecutionListWrapper() {
    final AbstractFuture<?> future = new AbstractFuture<Object>() {};
    @Override public void add(Runnable runnable, Executor executor) {
      future.addListener(runnable, executor);
    }

    @Override public void execute() {
      future.set(null);
    }

    @Override public Object getImpl() {
      return future;
    }
  };
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:17,代碼來源:ExecutionListBenchmark.java

示例10: asyncWriteFileObject

import java.util.concurrent.Executor; //導入依賴的package包/類
@NonNull
public static PrefetchableJavaFileObject asyncWriteFileObject(
    @NonNull final File file,
    @NonNull final File root,
    @NullAllowed JavaFileFilterImplementation filter,
    @NullAllowed Charset encoding,
    @NonNull final Executor pool,
    @NonNull final CompletionHandler<Void,Void> done) {
    final String[] pkgNamePair = getFolderAndBaseName(getRelativePath(root,file),File.separatorChar);
    return new AsyncWriteFileObject(
        file,
        convertFolder2Package(pkgNamePair[0], File.separatorChar),
        pkgNamePair[1],
        filter,
        encoding,
        pool,
        done);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:FileObjects.java

示例11: testOutgoingStreamContextIsNullIfContactIsNotFound

import java.util.concurrent.Executor; //導入依賴的package包/類
@Test
public void testOutgoingStreamContextIsNullIfContactIsNotFound()
		throws Exception {
	Mockery context = new Mockery();
	final DatabaseComponent db = context.mock(DatabaseComponent.class);
	final CryptoComponent crypto = context.mock(CryptoComponent.class);
	final Executor dbExecutor = context.mock(Executor.class);
	final ScheduledExecutorService scheduler =
			context.mock(ScheduledExecutorService.class);
	final Clock clock = context.mock(Clock.class);

	final Transaction txn = new Transaction(null, false);

	TransportKeyManager
			transportKeyManager = new TransportKeyManagerImpl(db,
			crypto, dbExecutor, scheduler, clock, transportId, maxLatency);
	assertNull(transportKeyManager.getStreamContext(txn, contactId));

	context.assertIsSatisfied();
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:21,代碼來源:TransportKeyManagerImplTest.java

示例12: setNetworkTimeout

import java.util.concurrent.Executor; //導入依賴的package包/類
@Override
public void setNetworkTimeout( Executor executor, int milliseconds )
    throws AlreadyClosedSqlException,
           JdbcApiSqlException,
           SQLFeatureNotSupportedException,
           SQLException {
  throwIfClosed();
  if ( null == executor ) {
    throw new InvalidParameterSqlException(
        "Invalid (null) \"executor\" parameter to setNetworkTimeout(...)" );
  }
  else if ( milliseconds < 0 ) {
    throw new InvalidParameterSqlException(
        "Invalid (negative) \"milliseconds\" parameter to"
        + " setNetworkTimeout(...) (" + milliseconds + ")" );
  }
  else {
    if ( 0 != milliseconds ) {
      throw new SQLFeatureNotSupportedException(
          "Setting network timeout is not supported." );
    }
  }
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:24,代碼來源:DremioConnectionImpl.java

示例13: testExecutors_nullCheck

import java.util.concurrent.Executor; //導入依賴的package包/類
public void testExecutors_nullCheck() throws Exception {
  new ClassSanityTester()
      .setDefault(RateLimiter.class, RateLimiter.create(1.0))
      .forAllPublicStaticMethods(MoreExecutors.class)
      .thatReturn(Executor.class)
      .testNulls();
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:8,代碼來源:MoreExecutorsTest.java

示例14: get

import java.util.concurrent.Executor; //導入依賴的package包/類
@Override public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations,
    Retrofit retrofit) {
  if (getRawType(returnType) != MyCall.class) {
    return null;
  }
  if (!(returnType instanceof ParameterizedType)) {
    throw new IllegalStateException(
        "MyCall must have generic type (e.g., MyCall<ResponseBody>)");
  }
  Type responseType = getParameterUpperBound(0, (ParameterizedType) returnType);
  Executor callbackExecutor = retrofit.callbackExecutor();
  return new ErrorHandlingCallAdapter<>(responseType, callbackExecutor);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:ErrorHandlingAdapter.java

示例15: AsyncExecutor

import java.util.concurrent.Executor; //導入依賴的package包/類
private AsyncExecutor(Executor threadPool, EventBus eventBus, Class<?> failureEventType, Object scope) {
    this.threadPool = threadPool;
    this.eventBus = eventBus;
    this.scope = scope;
    try {
        failureEventConstructor = failureEventType.getConstructor(Throwable.class);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(
                "Failure event class must have a constructor with one parameter of type Throwable", e);
    }
}
 
開發者ID:weileng11,項目名稱:KUtils-master,代碼行數:12,代碼來源:AsyncExecutor.java


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