当前位置: 首页>>代码示例>>Java>>正文


Java Executor.execute方法代码示例

本文整理汇总了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);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:SimpleApplicationEventMulticaster.java

示例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);
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:17,代码来源:SafeApplicationEventMulticaster.java

示例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));
    }
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:17,代码来源:ConnectionImpl.java

示例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;
}
 
开发者ID:retrostreams,项目名称:android-retrofuture,代码行数:19,代码来源:CompletableFuture.java

示例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);
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:16,代码来源:ImmediateFuture.java

示例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);
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:18,代码来源:ExecutionList.java

示例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();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:9,代码来源:MoreExecutorsDirectExecutorBenchmark.java

示例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);
                }
            }
        }
    });
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:31,代码来源:NettyMessage.java

示例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");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:AsExecutor.java

示例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));
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:29,代码来源:ModelStore.java

示例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 );
        }
    };
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:16,代码来源:HiveCommon.java

示例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.
      }
    }
  };
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:40,代码来源:MoreExecutors.java

示例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();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:Connectors.java

示例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()));
}
 
开发者ID:lemnik,项目名称:actionchain,代码行数:4,代码来源:ActionCommand.java

示例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);
            }
        }
    });
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:53,代码来源:ConnectionImpl.java


注:本文中的java.util.concurrent.Executor.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。