本文整理汇总了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?") //
))) //
);
}
示例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;
}));
}
示例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);
}
示例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;
}
};
}
示例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();
}
示例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();
}
示例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();
}
示例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 );
}
};
}
示例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;
}
};
}
示例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);
}
示例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();
}
示例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." );
}
}
}
示例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();
}
示例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);
}
示例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);
}
}