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


Java TaskExecutor.execute方法代碼示例

本文整理匯總了Java中org.springframework.core.task.TaskExecutor.execute方法的典型用法代碼示例。如果您正苦於以下問題:Java TaskExecutor.execute方法的具體用法?Java TaskExecutor.execute怎麽用?Java TaskExecutor.execute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.core.task.TaskExecutor的用法示例。


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

示例1: getWebSocketConsumersManager

import org.springframework.core.task.TaskExecutor; //導入方法依賴的package包/類
/**
 * Manages kafka consumers running in a background processing thread for websocket consumers.
 * @param webKafkaConsumerFactory Factory for creating new Consumers
 * @param messagingTemplate messaging template instance for passing websocket messages.
 * @param backgroundConsumerExecutor The executor to run our manager in.
 * @param appProperties defined app properties.
 * @return manager instance for web socket consumers.
 */
@Bean
public WebSocketConsumersManager getWebSocketConsumersManager(
    final WebKafkaConsumerFactory webKafkaConsumerFactory,
    final SimpMessagingTemplate messagingTemplate,
    final TaskExecutor backgroundConsumerExecutor,
    final AppProperties appProperties) {

    // Create manager
    final WebSocketConsumersManager manager = new WebSocketConsumersManager(
        webKafkaConsumerFactory,
        messagingTemplate,
        appProperties.getMaxConcurrentWebSocketConsumers()
    );

    // Submit to executor service
    backgroundConsumerExecutor.execute(manager);

    return manager;
}
 
開發者ID:SourceLabOrg,項目名稱:kafka-webview,代碼行數:28,代碼來源:WebSocketConfig.java

示例2: requestAsync

import org.springframework.core.task.TaskExecutor; //導入方法依賴的package包/類
public static <T> DeferredResult<T> requestAsync(final TaskExecutor executor,
    final Callable<T> action) {
    final DeferredResult<T> result = new DeferredResult<>();

    final Runnable beforeCallable = () -> {
        try {
            T t = action.call();

            if (result.isSetOrExpired()) {
                log.error("async request expired");
                return;
            }

            result.setResult(t);
        } catch (final Exception ex) {
            result.setErrorResult(ex);
        }
    };

    executor.execute(beforeCallable);
    return result;
}
 
開發者ID:rsdomingues,項目名稱:wiredtigervsvmap,代碼行數:23,代碼來源:DeferredResultAdapter.java

示例3: testGetAsyncExecutor

import org.springframework.core.task.TaskExecutor; //導入方法依賴的package包/類
@Test
public void testGetAsyncExecutor() throws Exception {
  AppConfig config = new AppConfig();
  TaskExecutor asyncExecutor = config.getAsyncExecutor();

  AtomicBoolean value = new AtomicBoolean(false);

  asyncExecutor.execute(() -> {
    try {
      Thread.sleep(250);
    } catch (InterruptedException e) {
    }

    value.set(true);
  });

  Assert.assertFalse(value.get());
}
 
開發者ID:tunguski,項目名稱:kosher,代碼行數:19,代碼來源:TestAppConfig.java

示例4: resume

import org.springframework.core.task.TaskExecutor; //導入方法依賴的package包/類
/**
*  Resumes the execution of this task. The task must be suspended and the method it runs
       *  must be suspendable or exceptions will be thrown.
 *
 *  Note that "resuming" in this case menas only to post a request for resumption by setting the status to ACTIVE.
       *  It is up to the method's compute implementation to check for this status and resume when it is detected.
       *
       *  <p>This method may also wait for the task to resume, but this may lead to the calling thread being
       *  permanently locked if the compute method never finishes.
       *
       *  Note that when second thread calls resume() on the same object, it will have to wait for the first thread to complete the call to this method.
       *
       * @param t executor of this task
       * @throws InvalidTaskStateException thrown when the task status doesn't allow resuming or the method
       *              isn't suspendable
       */
public void resume(TaskExecutor t) throws InvalidTaskStateException {
	synchronized (this) {

		if (!(method instanceof SuspendableMethod) || !status.isResumable()) {
			throw new InvalidTaskStateException("error.taskNotSuspendable");
		}
		status = TaskStatus.ACTIVE;
		info.setResumeTime(new Date());
		fireTaskResumed();
		notifyAll();
		if (t == null) {
			(new Thread(this)).start();
		} else {
			t.execute(this);
		}
		debug("Task resumed");
	}
}
 
開發者ID:BrainTech,項目名稱:svarog,代碼行數:35,代碼來源:LocalTask.java

示例5: copyActivityFeed

import org.springframework.core.task.TaskExecutor; //導入方法依賴的package包/類
public void copyActivityFeed( final EntityRef connectingEntity, final EntityRef connectedEntityRef )
        throws Exception {
    if (logger.isTraceEnabled()) {
        logger.trace("Copying activities to feed...");
    }
    TaskExecutor taskExecutor = ( TaskExecutor ) getApplicationContext().getBean( "taskExecutor" );
    taskExecutor.execute( new Runnable() {
        @Override
        public void run() {
            try {
                em.copyRelationships( connectedEntityRef, "activities", connectingEntity, "feed" );
            }
            catch ( Exception e ) {
                logger.error( "Error while copying activities into feed", e );
            }
        }
    } );
}
 
開發者ID:apache,項目名稱:usergrid,代碼行數:19,代碼來源:FollowingService.java

示例6: execute

import org.springframework.core.task.TaskExecutor; //導入方法依賴的package包/類
public static boolean execute(Runnable task, long waitTime, TaskExecutor taskExecutor) {
	Assert.notNull(task);

	Counter counter = new Counter("counter for task: " + task);
	Runnable wrapper = new MonitoredRunnable(task, counter);

	boolean internallyManaged = false;

	if (taskExecutor == null) {
		taskExecutor = new SimpleTaskExecutor();
		internallyManaged = true;
	}

	counter.increment();

	taskExecutor.execute(wrapper);

	if (counter.waitForZero(waitTime)) {
		log.error(task + " did not finish in " + waitTime
				+ "ms; consider taking a snapshot and then shutdown the VM in case the thread still hangs");

		//log.error("Current Thread dump***\n" + ThreadDump.dumpThreads());

		if (internallyManaged) {
			try {
				((DisposableBean) taskExecutor).destroy();
			} catch (Exception e) {
				log.error("Exception thrown while destroying internally managed thread executor", e);
			}
		}
		return true;
	}

	return false;
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:36,代碼來源:RunnableTimedExecution.java

示例7: schedulingRunner

import org.springframework.core.task.TaskExecutor; //導入方法依賴的package包/類
@Bean
public CommandLineRunner schedulingRunner(final TaskExecutor executor, final AmqpAdmin amqpAdmin, final ProcessService processStarter) {
    return args -> executor.execute(() -> {
        
        // Init Rabbit exchange and queue
        amqpAdmin.deleteExchange(EXCHANGE);
        TopicExchange exchange = new TopicExchange(EXCHANGE);
        amqpAdmin.declareExchange(exchange);
        Queue queue = new Queue("flowable-history-jobs", true);
        amqpAdmin.declareQueue(queue);
        amqpAdmin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("flowable-history-jobs"));
      
    });
}
 
開發者ID:flowable,項目名稱:flowable-examples,代碼行數:15,代碼來源:ProcessApplication.java

示例8: start

import org.springframework.core.task.TaskExecutor; //導入方法依賴的package包/類
/**
* Prepares starting the execution of the task (the computation) on the new thread if specified TaskExecutor is null, otherwise by this TaskExecutor.
 * Note that "starting" in this case menas only to post a request for starting by setting the status to ACTIVE_WAITING.
       * Note that when second thread calls start() on the same object, it will have to wait for the first thread to complete the call to this method.
       * @param t executor of Task
 * @throws InvalidTaskStateException thrown when the task status doesn't allow starting
 */
public void start(TaskExecutor t) throws InvalidTaskStateException {
	synchronized (this) {
		if (!status.isStartable()) {
			throw new InvalidTaskStateException("error.taskStatusMustBeNew");
		}
		status = TaskStatus.ACTIVE_WAITING;
		if (t == null) {
			(new Thread(this)).start();
		} else {
			t.execute(this);
		}
		debug("Task started");
	}
}
 
開發者ID:BrainTech,項目名稱:svarog,代碼行數:22,代碼來源:LocalTask.java

示例9: execute

import org.springframework.core.task.TaskExecutor; //導入方法依賴的package包/類
public static boolean execute(Runnable task, long waitTime, TaskExecutor taskExecutor) {
	Assert.notNull(task);

	Counter counter = new Counter("counter for task: " + task);
	Runnable wrapper = new MonitoredRunnable(task, counter);

	boolean internallyManaged = false;

	if (taskExecutor == null) {
		taskExecutor = new SimpleTaskExecutor();
		internallyManaged = true;
	}

	counter.increment();

	taskExecutor.execute(wrapper);

	if (counter.waitForZero(waitTime)) {
		log.error(task + " did not finish in " + waitTime
				+ "ms; consider taking a snapshot and then shutdown the VM in case the thread still hangs");

		if (internallyManaged) {
			try {
				((DisposableBean) taskExecutor).destroy();
			}
			catch (Exception e) {
				// no exception is thrown, nothing to worry
			}
		}
		return true;
	}

	return false;
}
 
開發者ID:BeamFoundry,項目名稱:spring-osgi,代碼行數:35,代碼來源:RunnableTimedExecution.java


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