use of java.util.concurrent.FutureTask in project spring-framework by spring-projects.
the class SimpleConfigTests method testFooService.
@Test
public void testFooService() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getConfigLocations(), getClass());
FooService fooService = ctx.getBean("fooServiceImpl", FooService.class);
ServiceInvocationCounter serviceInvocationCounter = ctx.getBean("serviceInvocationCounter", ServiceInvocationCounter.class);
String value = fooService.foo(1);
assertEquals("bar", value);
Future<?> future = fooService.asyncFoo(1);
assertTrue(future instanceof FutureTask);
assertEquals("bar", future.get());
assertEquals(2, serviceInvocationCounter.getCount());
fooService.foo(1);
assertEquals(3, serviceInvocationCounter.getCount());
}
use of java.util.concurrent.FutureTask in project spring-framework by spring-projects.
the class ThreadPoolExecutorFactoryBeanTests method defaultExecutor.
@Test
public void defaultExecutor() throws Exception {
ApplicationContext context = new AnnotationConfigApplicationContext(ExecutorConfig.class);
ExecutorService executor = context.getBean("executor", ExecutorService.class);
FutureTask<String> task = new FutureTask<>(new Callable<String>() {
@Override
public String call() throws Exception {
return "foo";
}
});
executor.execute(task);
assertEquals("foo", task.get());
}
use of java.util.concurrent.FutureTask in project spring-framework by spring-projects.
the class TaskExecutorAdapter method submit.
@Override
public Future<?> submit(Runnable task) {
try {
if (this.taskDecorator == null && this.concurrentExecutor instanceof ExecutorService) {
return ((ExecutorService) this.concurrentExecutor).submit(task);
} else {
FutureTask<Object> future = new FutureTask<>(task, null);
doExecute(this.concurrentExecutor, this.taskDecorator, future);
return future;
}
} catch (RejectedExecutionException ex) {
throw new TaskRejectedException("Executor [" + this.concurrentExecutor + "] did not accept task: " + task, ex);
}
}
use of java.util.concurrent.FutureTask in project siena by mandubian.
the class BaseMultiThreadTest method testMultiThreadSimple.
public void testMultiThreadSimple() {
int count = 0;
while (count < 1000) {
count++;
logger.info("Launching " + count + "-th operation");
final int c = count;
FutureTask task = new FutureTask<Object>(new Thread() {
public void run() {
Model.getByKey(PersonLongAutoIDModel.class, PERSON_LONGAUTOID_TESLA.id);
logger.info("Executed " + c + "-th operation");
}
}, null);
Thread thread = new Thread(task);
thread.start();
try {
task.get(1l, TimeUnit.HOURS);
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of java.util.concurrent.FutureTask in project Denizen-For-Bukkit by DenizenScript.
the class ChatTrigger method asyncChatTrigger.
@EventHandler
public void asyncChatTrigger(final AsyncPlayerChatEvent event) {
if (HyperDebug) {
dB.log("Chat trigger seen, cancelled: " + event.isCancelled() + ", chatasync: " + Settings.chatAsynchronous());
}
if (event.isCancelled()) {
return;
}
// Return if "Use asynchronous event" is false in config file
if (!Settings.chatAsynchronous()) {
return;
}
if (!event.isAsynchronous()) {
syncChatTrigger(new PlayerChatEvent(event.getPlayer(), event.getMessage(), event.getFormat(), event.getRecipients()));
return;
}
FutureTask<ChatContext> futureTask = new FutureTask<ChatContext>(new Callable<ChatContext>() {
@Override
public ChatContext call() {
return process(event.getPlayer(), event.getMessage());
}
});
Bukkit.getScheduler().runTask(DenizenAPI.getCurrentInstance(), futureTask);
try {
ChatContext context = futureTask.get();
if (context.wasTriggered()) {
event.setCancelled(true);
}
if (context.hasChanges()) {
event.setMessage(context.getChanges());
}
} catch (Exception e) {
dB.echoError(e);
}
}
Aggregations