本文整理汇总了Java中java.util.concurrent.Executor.execute方法的典型用法代码示例。如果您正苦于以下问题:Java Executor.execute方法的具体用法?Java Executor.execute怎么用?Java Executor.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.Executor
的用法示例。
在下文中一共展示了Executor.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: multicastEvent
import java.util.concurrent.Executor; //导入方法依赖的package包/类
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void multicastEvent(final ApplicationEvent event) {
for (final ApplicationListener listener : getApplicationListeners(event)) {
Executor executor = getTaskExecutor();
if (executor != null) {
executor.execute(new Runnable() {
@Override
public void run() {
listener.onApplicationEvent(event);
}
});
}
else {
listener.onApplicationEvent(event);
}
}
}
示例2: multicastEventInternal
import java.util.concurrent.Executor; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected void multicastEventInternal(final ApplicationEvent event) {
for (final ApplicationListener listener : getApplicationListeners(event)) {
Executor executor = getTaskExecutor();
if (executor != null) {
executor.execute(new Runnable() {
public void run() {
listener.onApplicationEvent(event);
}
});
}
else {
listener.onApplicationEvent(event);
}
}
}
示例3: setNetworkTimeout
import java.util.concurrent.Executor; //导入方法依赖的package包/类
public void setNetworkTimeout(Executor executor, final int milliseconds) throws SQLException {
synchronized (getConnectionMutex()) {
SecurityManager sec = System.getSecurityManager();
if (sec != null) {
sec.checkPermission(SET_NETWORK_TIMEOUT_PERM);
}
if (executor == null) {
throw SQLError.createSQLException("Executor can not be null", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
}
checkClosed();
executor.execute(new NetworkTimeoutSetter(this, this.io, milliseconds));
}
}
示例4: uniWhenCompleteStage
import java.util.concurrent.Executor; //导入方法依赖的package包/类
private CompletableFuture<T> uniWhenCompleteStage(
Executor e, BiConsumer<? super T, ? super Throwable> f) {
Objects.requireNonNull(f);
CompletableFuture<T> d = newIncompleteFuture();
Object r;
if ((r = result) == null)
unipush(new UniWhenComplete<T>(e, d, this, f));
else if (e == null)
d.uniWhenComplete(r, f, null);
else {
try {
e.execute(new UniWhenComplete<T>(null, d, this, f));
} catch (Throwable ex) {
d.result = encodeThrowable(ex);
}
}
return d;
}
示例5: addListener
import java.util.concurrent.Executor; //导入方法依赖的package包/类
@Override
public void addListener(Runnable listener, Executor executor) {
checkNotNull(listener, "Runnable was null.");
checkNotNull(executor, "Executor was null.");
try {
executor.execute(listener);
} catch (RuntimeException e) {
// ListenableFuture's contract is that it will not throw unchecked exceptions, so log the bad
// runnable and/or executor and swallow it.
log.log(
Level.SEVERE,
"RuntimeException while executing runnable " + listener + " with executor " + executor,
e);
}
}
示例6: executeListener
import java.util.concurrent.Executor; //导入方法依赖的package包/类
/**
* Submits the given runnable to the given {@link Executor} catching and logging all {@linkplain
* RuntimeException runtime exceptions} thrown by the executor.
*/
private static void executeListener(Runnable runnable, Executor executor) {
try {
executor.execute(runnable);
} catch (RuntimeException e) {
// Log it and keep going -- bad runnable and/or executor. Don't punish the other runnables if
// we're given a bad one. We only catch RuntimeException because we want Errors to propagate
// up.
log.log(
Level.SEVERE,
"RuntimeException while executing runnable " + runnable + " with executor " + executor,
e);
}
}
示例7: timeUncontendedExecute
import java.util.concurrent.Executor; //导入方法依赖的package包/类
@Benchmark int timeUncontendedExecute(int reps) {
final Executor executor = this.executor;
final CountingRunnable countingRunnable = this.countingRunnable;
for (int i = 0; i < reps; i++) {
executor.execute(countingRunnable);
}
return countingRunnable.integer.get();
}
示例8: handleAsync
import java.util.concurrent.Executor; //导入方法依赖的package包/类
@Override
public void handleAsync(Executor worker, Consumer<Object> handler, Consumer<Throwable> onError) {
ArgAssert.notNull(worker, "Worker");
ArgAssert.notNull(handler, "Handler");
ArgAssert.notNull(onError, "Error consumer");
buf.retain();
worker.execute(() -> {
try {
Object msg;
try {
msg = decode();
} finally {
buf.release();
}
handler.accept(msg);
} catch (Throwable t) {
try {
onError.accept(t);
} catch (RuntimeException | Error e) {
if (log != null && log.isErrorEnabled()) {
log.error("Got an unexpected runtime error while notifying callback on another error [cause={}]", t.toString(), e);
}
}
}
});
}
示例9: testAttackingTask
import java.util.concurrent.Executor; //导入方法依赖的package包/类
static void testAttackingTask(AsynchronousChannelGroup group) throws Exception {
Executor executor = (Executor)group;
Attack task = new Attack();
executor.execute(task);
task.waitUntilDone();
if (!task.failedDueToSecurityException())
throw new RuntimeException("SecurityException expected");
}
示例10: handleUpdate
import java.util.concurrent.Executor; //导入方法依赖的package包/类
private void handleUpdate(String id, @Nullable T after, Executor notificationExecutor) {
final T before = byId.get(id);
final T latest;
if(exists(before)) {
if(exists(after)) {
logAction("Update", after);
unindex(before);
reindex(after);
latest = after;
} else {
logAction("Delete", before);
unindex(before);
remove(before);
latest = before;
}
} else if(exists(after)) {
logAction("Create", after);
reindex(after);
latest = after;
} else {
latest = null;
}
if(exists(latest)) {
notificationExecutor.execute(() -> dispatcher.modelUpdated(before, after, latest));
}
}
示例11: getOperationService
import java.util.concurrent.Executor; //导入方法依赖的package包/类
public Executor getOperationService ()
{
return new Executor () {
@Override
public void execute ( final Runnable command )
{
final Executor executor = getOperationServiceInstance ();
if ( executor == null )
{
throw new IllegalStateException ( "Hive is disposed" );
}
executor.execute ( command );
}
};
}
示例12: rejectionPropagatingExecutor
import java.util.concurrent.Executor; //导入方法依赖的package包/类
/**
* Returns an Executor that will propagate {@link RejectedExecutionException} from the delegate
* executor to the given {@code future}.
*
* <p>Note, the returned executor can only be used once.
*/
static Executor rejectionPropagatingExecutor(
final Executor delegate, final AbstractFuture<?> future) {
checkNotNull(delegate);
checkNotNull(future);
if (delegate == directExecutor()) {
// directExecutor() cannot throw RejectedExecutionException
return delegate;
}
return new Executor() {
volatile boolean thrownFromDelegate = true;
@Override
public void execute(final Runnable command) {
try {
delegate.execute(
new Runnable() {
@Override
public void run() {
thrownFromDelegate = false;
command.run();
}
});
} catch (RejectedExecutionException e) {
if (thrownFromDelegate) {
// wrap exception?
future.setException(e);
}
// otherwise it must have been thrown from a transitive call and the delegate runnable
// should have handled it.
}
}
};
}
示例13: executeRootHandler
import java.util.concurrent.Executor; //导入方法依赖的package包/类
public static void executeRootHandler(final HttpHandler handler, final HttpServerExchange exchange) {
try {
exchange.setInCall(true);
handler.handleRequest(exchange);
exchange.setInCall(false);
boolean resumed = exchange.runResumeReadWrite();
if (exchange.isDispatched()) {
if (resumed) {
throw new RuntimeException("resumed and dispatched");
}
final Runnable dispatchTask = exchange.getDispatchTask();
Executor executor = exchange.getDispatchExecutor();
exchange.setDispatchExecutor(null);
exchange.unDispatch();
if (dispatchTask != null) {
executor = executor == null ? exchange.getConnection().getWorker() : executor;
executor.execute(dispatchTask);
}
} else if (!resumed) {
exchange.endExchange();
}
} catch (Throwable t) {
exchange.setInCall(false);
if (!exchange.isResponseStarted()) {
exchange.setResponseCode(StatusCodes.INTERNAL_SERVER_ERROR);
}
UndertowLogger.REQUEST_LOGGER.errorf(t, "Undertow request failed %s", exchange);
exchange.endExchange();
}
}
示例14: exec
import java.util.concurrent.Executor; //导入方法依赖的package包/类
public void exec(final P parameter, final Executor background) {
background.execute(new ActionCommandRunner(background, parameter, chain.iterator()));
}
示例15: abort
import java.util.concurrent.Executor; //导入方法依赖的package包/类
/**
* Terminates an open connection. Calling <code>abort</code> results in:
* <ul>
* <li>The connection marked as closed
* <li>Closes any physical connection to the database
* <li>Releases resources used by the connection
* <li>Insures that any thread that is currently accessing the connection will either progress to completion or throw an <code>SQLException</code>.
* </ul>
* <p>
* Calling <code>abort</code> marks the connection closed and releases any resources. Calling <code>abort</code> on a closed connection is a no-op.
* <p>
* It is possible that the aborting and releasing of the resources that are held by the connection can take an extended period of time. When the
* <code>abort</code> method returns, the connection will have been marked as closed and the <code>Executor</code> that was passed as a parameter to abort
* may still be executing tasks to release resources.
* <p>
* This method checks to see that there is an <code>SQLPermission</code> object before allowing the method to proceed. If a <code>SecurityManager</code>
* exists and its <code>checkPermission</code> method denies calling <code>abort</code>, this method throws a <code>java.lang.SecurityException</code>.
*
* @param executor
* The <code>Executor</code> implementation which will
* be used by <code>abort</code>.
* @throws java.sql.SQLException
* if a database access error occurs or
* the {@code executor} is {@code null},
* @throws java.lang.SecurityException
* if a security manager exists and its <code>checkPermission</code> method denies calling <code>abort</code>
* @see SecurityManager#checkPermission
* @see Executor
* @since 1.7
*/
public void abort(Executor executor) throws SQLException {
SecurityManager sec = System.getSecurityManager();
if (sec != null) {
sec.checkPermission(ABORT_PERM);
}
if (executor == null) {
throw SQLError.createSQLException("Executor can not be null", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
}
executor.execute(new Runnable() {
public void run() {
try {
abortInternal();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
});
}