當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。