本文整理汇总了Java中java.util.concurrent.FutureTask.run方法的典型用法代码示例。如果您正苦于以下问题:Java FutureTask.run方法的具体用法?Java FutureTask.run怎么用?Java FutureTask.run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.FutureTask
的用法示例。
在下文中一共展示了FutureTask.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <P extends EasyTransRequest<R,E>,E extends EasyTransExecutor,R extends Serializable> Future<R> execute(final Integer callSeq, final P params) {
MessageRecordContent content = new MessageRecordContent();
content.setParams(params);
content.setCallSeq(callSeq);
transSynchronizer.registerLog(content);
final PublishResult result = new PublishResult();
result.setMessageContentId(content.getcId());
FutureTask<PublishResult> future = new FutureTask<PublishResult>(new Callable<PublishResult>() {
@Override
public PublishResult call() throws Exception {
return result;
}
});
future.run();
return (Future<R>) future;
}
示例2: checkIsRunning
import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
void checkIsRunning(Future<?> f) {
checkNotDone(f);
if (f instanceof FutureTask) {
FutureTask ft = (FutureTask<?>) f;
// Check that run methods do nothing
ft.run();
if (f instanceof PublicFutureTask) {
PublicFutureTask pf = (PublicFutureTask) f;
int savedRunCount = pf.runCount();
pf.run();
assertFalse(pf.runAndReset());
assertEquals(savedRunCount, pf.runCount());
}
checkNotDone(f);
}
}
示例3: runTask
import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
@Nullable
public static <V> V runTask(FutureTask<V> task, Logger logger)
{
try
{
task.run();
return task.get();
}
catch (ExecutionException executionexception)
{
logger.fatal((String)"Error executing task", (Throwable)executionexception);
}
catch (InterruptedException interruptedexception)
{
logger.fatal((String)"Error executing task", (Throwable)interruptedexception);
}
return (V)null;
}
示例4: func_181617_a
import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
public static <V> V func_181617_a(FutureTask<V> p_181617_0_, Logger p_181617_1_)
{
try
{
p_181617_0_.run();
return p_181617_0_.get();
}
catch (ExecutionException executionexception)
{
p_181617_1_.fatal((String)"Error executing task", (Throwable)executionexception);
}
catch (InterruptedException interruptedexception)
{
p_181617_1_.fatal((String)"Error executing task", (Throwable)interruptedexception);
}
return (V)null;
}
示例5: testGet_NegativeInfinityTimeout
import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
/**
* timed get with most negative timeout works correctly (i.e. no
* underflow bug)
*/
public void testGet_NegativeInfinityTimeout() throws Exception {
final ExecutorService pool = Executors.newFixedThreadPool(10);
final Runnable nop = new Runnable() { public void run() {}};
final FutureTask<Void> task = new FutureTask<>(nop, null);
final List<Future<?>> futures = new ArrayList<>();
Runnable r = new Runnable() { public void run() {
for (long timeout : new long[] { 0L, -1L, Long.MIN_VALUE }) {
try {
task.get(timeout, NANOSECONDS);
shouldThrow();
} catch (TimeoutException success) {
} catch (Throwable fail) {threadUnexpectedException(fail);}}}};
for (int i = 0; i < 10; i++)
futures.add(pool.submit(r));
try {
joinPool(pool);
for (Future<?> future : futures)
checkCompletedNormally(future, null);
} finally {
task.run(); // last resort to help terminate
}
}
示例6: call
import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
private <T> Future<T> call(Callable callable, boolean async){
if(async){
return Pool.submit(callable);
}else{
FutureTask<T> future = new FutureTask(callable);
future.run();
return future;
}
}
示例7: execute
import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <P extends EasyTransRequest<R,E>,E extends EasyTransExecutor,R extends Serializable> Future<R> execute(final Integer sameBusinessCallSeq, final P params) {
FutureTask<PublishResult> future = new FutureTask<PublishResult>(new Callable<PublishResult>() {
@Override
public PublishResult call() throws Exception {
return new PublishResult();//do nothing
}
});
future.run();
final LogProcessContext logProcessContext = transSynchronizer.getLogProcessContext();
//sent message after transaction commit
logProcessContext.registerProcessEndEventListener(new GuardianProcessEndEventHandler() {
@Override
public boolean beforeProcessEnd(LogProcessContext logContext) {
if(logProcessContext.getFinalMasterTransStatus()){
BusinessIdentifer businessIdentifer = ReflectUtil.getBusinessIdentifer(params.getClass());
String messageId = getMessageId("M" + logProcessContext.getAndIncTransUniqueId(), logContext.getTransactionId());
publisher.publish(businessIdentifer.appId(), businessIdentifer.busCode(), sameBusinessCallSeq, messageId, params,logProcessContext);
LOG.info("Best effort message sent." + messageId);
}
return true;
}
});
return (Future<R>) future;
}
示例8: resolve
import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
@Override
public Future<Result> resolve() {
FutureTask<Result> toRet = new FutureTask<Result>(new Callable<Result>() {
@Override
public Result call() throws Exception {
NotifyDescriptor.Confirmation action = new NotifyDescriptor.Confirmation("You can either define netbeans.installation property in .m2/settings.xml file to point to currently running IDE or open the associated nbm-application project.", "Resolve missing NetBeans platform");
String prop = "Define property";
String open = "Open Application project";
action.setOptions(new Object[] { prop, open, NotifyDescriptor.CANCEL_OPTION});
Object result = DialogDisplayer.getDefault().notify(action);
if (prop.equals(result)) {
RunIDEInstallationChecker.setRunningIDEAsInstallation();
return Result.create(Status.RESOLVED);
}
if (open.equals(result)) {
final Action act = FileUtil.getConfigObject("Actions/Project/org-netbeans-modules-project-ui-OpenProject.instance", Action.class);
if (act != null) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
act.actionPerformed(null);
}
});
}
}
return Result.create(Status.UNRESOLVED);
}
});
toRet.run();
return toRet;
}
示例9: resolve
import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
/**
* Resolves the problem.
* Called by the Event Dispatch Thread.
* When the resolution needs to be done by a background thread, eg. downloading
* an archive from repository, the implementation directly returns
* a {@link Future} which is completed by the background thread.
* @return the {@link Future} holding the problem resolution status.
*/
public Future<Result> resolve() {
if (resolver == null) {
FutureTask<Result> toRet = new FutureTask<Result>(new Runnable() {
@Override
public void run() {
//noop
}
}, Result.create(Status.UNRESOLVED));
toRet.run();
return toRet;
}
return resolver.resolve();
}
示例10: compute
import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
/**
* Here I implemented following logic:
* if it is requested to fetch the data and the same request is in progress -
* result that returned is taken from the original one.
* once task is completed, it is removed from cache!
*
*/
@Override
public R compute(final P arg) throws InterruptedException {
Future<R> f = cache.get(arg);
if (f == null) {
Callable<R> evaluation = new Callable<R>() {
@Override
public R call() throws InterruptedException {
return computable.compute(arg);
}
};
FutureTask<R> ft = new FutureTask<>(evaluation);
f = cache.putIfAbsent(arg, ft);
if (f == null) {
f = ft;
ft.run();
}
}
try {
return f.get();
} catch (InterruptedException ex) {
cache.remove(arg, f);
throw new CancellationException(ex.getMessage());
} catch (Throwable th) {
cache.remove(arg, f);
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE, "TasksCachedProcessor: exception while task execution:", th); // NOI18N
}
throw new CancellationException(th.getMessage());
} finally {
if (removeOnCompletion) {
cache.remove(arg, f);
}
}
}
示例11: runOnUiThread
import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
/**
* Run the supplied FutureTask on the main thread. The method will block only if the current
* thread is the main thread.
*
* @param task The FutureTask to run
* @return The queried task (to aid inline construction)
*/
public static <T> FutureTask<T> runOnUiThread(FutureTask<T> task) {
if (runningOnUiThread()) {
task.run();
} else {
postOnUiThread(task);
}
return task;
}
示例12: testFuture
import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
@Test
public void testFuture() throws Exception {
FutureTask<Object> future = new FutureTask<>(() -> null);
future.run();
RxNullable.fromFuture(future)
.onNullDrop()
.observable()
.test()
.assertValueCount(0);
RxNullable.fromFuture(future)
.onNullDrop()
.flowable()
.test()
.assertValueCount(0);
}
示例13: _createEntrySafely
import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
/**
* Creates and returns an Entry instance in a thread-safe manner.
*/
private Entry _createEntrySafely(
final StyleContext context,
final StyleSheetDocument document,
final ConcurrentMap<Key, Future<Entry>> cache,
final Key key,
final Map<String, String> shortStyleClassMap,
final String[] namespacePrefixes,
final boolean checkModified,
final boolean isDirty)
{
// See JCIP 5.6 if you are confused by what we are doing here.
Callable<Entry> entryCreator = new Callable<Entry>() {
@Override
public Entry call()
{
return _createEntry(context,
document,
shortStyleClassMap,
namespacePrefixes,
checkModified,
isDirty);
}
};
FutureTask<Entry> ft = new FutureTask<Entry>(entryCreator);
Future<Entry> f = cache.putIfAbsent(key, ft);
if (f == null)
{
f = ft;
ft.run();
}
return _getEntryFromFuture(context, document, cache, key, f);
}
示例14: createNewAsyncThread
import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
private static Thread createNewAsyncThread(FutureTask<BigDecimal> task) {
return new Thread(new Runnable() {
@Override
public void run() {
task.run();
}
});
}
示例15: testReadFromNullReader
import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
/**
* Check that we do not stop responding when trying to read after adding null readers.
*/
@Test
@Category(value = ExcludeFromGatedCheckin.class)
public final void testReadFromNullReader() throws SQLException {
// The code below exposes a flaw in our current implementation related to
// CompleteResults semantics and the internal c-tor. The flaw does not
// leak out to customers because the MultiShardStatement object manages the
// necessary logic, but we need to patch the flaw so it doesn't end up
// inadvertently leaking out to customers.
// See VSTS 2616238 (i believe). Philip will be modofying logic and
// augmenting tests to deal with this issue.
// Pass a null reader and verify that read goes through and does not terminate.
LabeledResultSet[] readers = new LabeledResultSet[2];
readers[0] = getReader(conn1, "select 1", "Test0");
readers[1] = null;
try (MultiShardResultSet sdr = new MultiShardResultSet(Arrays.asList(readers))) {
FutureTask task = new FutureTask<>(() -> {
int count = 0;
while (sdr.next()) {
count++;
}
return count;
});
task.run();
Thread.sleep(500);
Assert.assertTrue("Read did not respond on the garbage reader.", task.isDone());
}
catch (SQLException | InterruptedException e) {
Assert.fail(e.getMessage());
}
}