本文整理汇总了Java中java.util.concurrent.Future.isDone方法的典型用法代码示例。如果您正苦于以下问题:Java Future.isDone方法的具体用法?Java Future.isDone怎么用?Java Future.isDone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.Future
的用法示例。
在下文中一共展示了Future.isDone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: demo1_Executor1
import java.util.concurrent.Future; //导入方法依赖的package包/类
private static void demo1_Executor1() {
System.out.println();
int shutdownDelaySec = 1;
ExecutorService execService = Executors.newSingleThreadExecutor();
Runnable runnable = () -> System.out.println("Worker One did the job.");
execService.execute(runnable);
runnable = () -> System.out.println("Worker Two did the job.");
Future future = execService.submit(runnable);
try {
execService.shutdown();
execService.awaitTermination(shutdownDelaySec, TimeUnit.SECONDS);
} catch (Exception ex) {
System.out.println("Caught around execService.awaitTermination(): " + ex.getClass().getName());
} finally {
if (!execService.isTerminated()) {
if (future != null && !future.isDone() && !future.isCancelled()) {
System.out.println("Cancelling the task...");
future.cancel(true);
}
}
List<Runnable> l = execService.shutdownNow();
System.out.println(l.size() + " tasks were waiting to be executed. Service stopped.");
}
}
示例2: shutdownAndCancelTask
import java.util.concurrent.Future; //导入方法依赖的package包/类
private static void shutdownAndCancelTask(ExecutorService execService, int shutdownDelaySec, String name, Future future) {
try {
execService.shutdown();
System.out.println("Waiting for " + shutdownDelaySec + " sec before shutting down service...");
execService.awaitTermination(shutdownDelaySec, TimeUnit.SECONDS);
} catch (Exception ex) {
System.out.println("Caught around execService.awaitTermination(): " + ex.getClass().getName());
} finally {
if (!execService.isTerminated()) {
System.out.println("Terminating remaining running tasks...");
if (future != null && !future.isDone() && !future.isCancelled()) {
System.out.println("Cancelling task " + name + "...");
future.cancel(true);
}
}
System.out.println("Calling execService.shutdownNow()...");
List<Runnable> l = execService.shutdownNow();
System.out.println(l.size() + " tasks were waiting to be executed. Service stopped.");
}
}
示例3: tillStop
import java.util.concurrent.Future; //导入方法依赖的package包/类
@Override
protected void tillStop() {
Future<?> future = this._future;
if (future == null
|| future.isCancelled()
|| future.isDone()) {
return;
}
try {
future.get();
} catch (CancellationException
| InterruptedException
| ExecutionException ex) {
// ignore
}
}
示例4: waitScanFinished
import java.util.concurrent.Future; //导入方法依赖的package包/类
/**
* Waits for the end of the initial scan, this helper method
* is designed for tests which require to wait for end of initial scan.
* @throws InterruptedException is thrown when the waiting thread is interrupted.
* @deprecated use {@link JavaSource#runWhenScanFinished}
*/
public static void waitScanFinished () throws InterruptedException {
try {
class T extends UserTask implements ClasspathInfoProvider {
private final ClassPath EMPTY_PATH = ClassPathSupport.createClassPath(new URL[0]);
private final ClasspathInfo cpinfo = ClasspathInfo.create(EMPTY_PATH, EMPTY_PATH, EMPTY_PATH);
@Override
public void run(ResultIterator resultIterator) throws Exception {
// no-op
}
@Override
public ClasspathInfo getClasspathInfo() {
return cpinfo;
}
}
Future<Void> f = ParserManager.parseWhenScanFinished(JavacParser.MIME_TYPE, new T());
if (!f.isDone()) {
f.get();
}
} catch (Exception ex) {
}
}
示例5: testIgnoredBySharabilityAWT
import java.util.concurrent.Future; //导入方法依赖的package包/类
public void testIgnoredBySharabilityAWT () throws Throwable {
final Throwable[] th = new Throwable[1];
Future<Project[]> projectOpenTask = OpenProjects.getDefault().openProjects();
if (!projectOpenTask.isDone()) {
try {
projectOpenTask.get();
} catch (Exception ex) {
// not interested
}
}
EventQueue.invokeAndWait(new Runnable() {
@Override
public void run() {
try {
skeletonIgnoredBySharability();
} catch (Throwable t) {
th[0] = t;
}
}
});
if (th[0] != null) {
throw th[0];
}
}
示例6: pollTask
import java.util.concurrent.Future; //导入方法依赖的package包/类
/**
* Check whether {@code Rows} have been merged to a task. If done, poll the task and return.
*
* @return a task need be loaded to database
* @throws BiremeException merge task failed
* @throws InterruptedException if the current thread was interrupted while waiting
*/
protected LoadTask pollTask() throws BiremeException, InterruptedException {
LoadTask task = null;
Future<LoadTask> head = taskIn.peek();
if (head != null && head.isDone()) {
taskIn.remove();
try {
task = head.get();
} catch (ExecutionException e) {
throw new BiremeException("Merge task failed.\n", e.getCause());
}
}
return task;
}
示例7: removedBundle
import java.util.concurrent.Future; //导入方法依赖的package包/类
@Override
public void removedBundle(final Bundle bundle, final BundleEvent event, final Future<T> object) {
if (!object.isDone() && object.cancel(false)) {
// We canceled adding event before it was processed
// so it is safe to return
LOG.trace("Adding Bundle event for {} was cancelled. No additional work required.", bundle);
return;
}
try {
LOG.trace("Invoking removedBundle event for {}", bundle);
primaryTracker.removedBundle(bundle, event, object.get());
forEachAdditionalBundle(tracker -> tracker.removedBundle(bundle, event, null));
LOG.trace("Removed bundle event for {} finished successfully.", bundle);
} catch (final ExecutionException | InterruptedException e) {
LOG.error("Failed to remove bundle {}", bundle, e);
}
}
示例8: isDelayed
import java.util.concurrent.Future; //导入方法依赖的package包/类
/**
* Delays given task if neccessary - e.g. projects are currently openning - and reschedules the task if indexing is running
* This method waits for projects to open and thus blocks the current thread.
* @param task task to be delayed
* @param logger
* @param logMessagePrefix
* @return true if the task was rescheduled
*/
public boolean isDelayed (RequestProcessor.Task task, Logger logger, String logMessagePrefix) {
boolean rescheduled = false;
DelayedScan scan = getRegisteredScan(task);
Future<Project[]> projectOpenTask = OpenProjects.getDefault().openProjects();
if (!projectOpenTask.isDone()) {
try {
projectOpenTask.get();
} catch (Exception ex) {
// not interested
}
}
if (IndexingBridge.getInstance().isIndexingInProgress()
&& (BLOCK_INDEFINITELY || scan.waitingLoops * WAITING_PERIOD < MAX_WAITING_TIME)) {
// do not steal disk from openning projects and indexing tasks
Level level = ++scan.waitingLoops < 10 ? Level.FINE : Level.INFO;
logger.log(level, "{0}: Scanning in progress, trying again in {1}ms", new Object[]{logMessagePrefix, WAITING_PERIOD}); //NOI18N
task.schedule(WAITING_PERIOD); // try again later
rescheduled = true;
} else {
scan.waitingLoops = 0;
}
return rescheduled;
}
示例9: getIndexingState
import java.util.concurrent.Future; //导入方法依赖的package包/类
@SuppressWarnings("UseSpecificCatch")
public Set<IndexingState> getIndexingState() {
boolean beforeInitialScanStarted;
synchronized (this) {
beforeInitialScanStarted = state == State.CREATED || state == State.STARTED;
}
// #168272
boolean openingProjects;
try {
final Future<Project []> f = globalOpenProjects.openProjects();
openingProjects = !f.isDone() || f.get().length > 0;
} catch (Exception ie) {
openingProjects = true;
}
final Set<IndexingState> result = EnumSet.noneOf(IndexingState.class);
final boolean starting = (beforeInitialScanStarted && openingProjects);
final boolean working = worker.isWorking();
final boolean pathChanging = !PathRegistry.getDefault().isFinished();
if (starting) {
result.add(IndexingState.STARTING);
}
if (pathChanging) {
result.add(IndexingState.PATH_CHANGING);
}
if (working) {
result.add(IndexingState.WORKING);
}
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE,
"IsScanInProgress: (starting: {0} | working: {1} | path are changing: {2})", //NOI18N
new Object[] {
starting,
working,
pathChanging
});
}
return result;
}
示例10: dispatch
import java.util.concurrent.Future; //导入方法依赖的package包/类
/**
* Get the transform result and dispatch.
*
* @throws BiremeException transform failed
* @throws InterruptedException if the current thread was interrupted while waiting
*/
public void dispatch() throws BiremeException, InterruptedException {
if (rowSet != null) {
complete = insertRowSet();
if (!complete) {
return;
}
}
while (!transResult.isEmpty() && !cxt.stop) {
Future<RowSet> head = transResult.peek();
if (head.isDone()) {
transResult.remove();
try {
rowSet = head.get();
} catch (ExecutionException e) {
throw new BiremeException("Transform failed.\n", e.getCause());
}
complete = insertRowSet();
if (!complete) {
break;
}
} else {
break;
}
}
}
示例11: isCompleted
import java.util.concurrent.Future; //导入方法依赖的package包/类
public static boolean isCompleted(Path path) {
Future<?> future = prefetchFutures.get(path);
if (future != null) {
return future.isDone();
}
return true;
}
示例12: enable
import java.util.concurrent.Future; //导入方法依赖的package包/类
/** Overrides superclass method. Adds additional test if i18n module has registered factory
* for this data object to be able to perform i18n action. */
@Override
protected boolean enable(Node[] activatedNodes) {
if (!super.enable(activatedNodes)) return false;
// if has an open editor pane must not be in a guarded block
// PENDING>>
// It causes StackOverflowError
// I18nSupport.isGuardedPosittion() checks teh way it causes change cookies (remove add SaveCookie), what
// in turn calls back enable method, it calls isGuardedPosition again etc. etc.
/*final SourceCookie.Editor sec = (SourceCookie.Editor)(activatedNodes[0]).getCookie(SourceCookie.Editor.class);
if (sec != null) {
JEditorPane[] edits = sec.getOpenedPanes();
if (edits != null && edits.length > 0) {
int position = edits[0].getCaret().getDot();
StyledDocument doc = sec.getDocument();
DataObject obj = (DataObject)sec.getSource().getCookie(DataObject.class);
if(I18nSupport.getI18nSupport(doc, obj).isGuardedPosition(position))
return false;
}
}*/
// PENDING<<
DataObject dataObject = activatedNodes[0].getCookie(DataObject.class);
if (dataObject == null) return false;
if (FactoryRegistry.hasFactory(dataObject.getClass()) == false) return false;
EditorCookie sec = (activatedNodes[0]).getCookie(EditorCookie.class);
if (sec == null || !hasOpenedPane(sec)) return false;
Future<Project[]> openProjects = OpenProjects.getDefault().openProjects();
if(!openProjects.isDone()) {
return false;
}
// check that the node has project
return FileOwnerQuery.getOwner(dataObject.getPrimaryFile()) != null;
}
示例13: isResultAvailable
import java.util.concurrent.Future; //导入方法依赖的package包/类
public boolean isResultAvailable(final P arg) {
Future<R> res = cache.get(arg);
if (res == null) {
return false;
}
return res.isDone() && !res.isCancelled();
}
示例14: poll
import java.util.concurrent.Future; //导入方法依赖的package包/类
private <T> Future<T> poll(List<Future<T>> futures) {
for (Future<T> future : futures) {
if (future.isDone()) {
return future;
}
}
return null;
}
示例15: enable
import java.util.concurrent.Future; //导入方法依赖的package包/类
/** Overrides superclass method. Adds additional test if i18n module has registered factory
* for this data object to be able to perform i18n action. */
protected boolean enable(Node[] activatedNodes) {
if (activatedNodes.length != 1) {
return false;
}
final Node node = activatedNodes[0];
DataObject dataObject = node.getCookie(DataObject.class);
if ((dataObject == null) || (dataObject.getPrimaryFile() == null)) {
return false;
}
EditorCookie editorCookie = node.getCookie(EditorCookie.class);
if (editorCookie == null) {
editorCookie = dataObject.getCookie(EditorCookie.class);
if (editorCookie == null) {
return false;
}
}
if (!FactoryRegistry.hasFactory(dataObject.getClass())) {
return false;
}
// check that the node has project
Future<Project[]> openProjects = OpenProjects.getDefault().openProjects();
if(!openProjects.isDone()) {
return true;
}
if (FileOwnerQuery.getOwner(dataObject.getPrimaryFile()) == null) {
return false;
}
return true;
}