FutureTask isCancelled - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for FutureTask isCancelled method.

This code example shows how to use the following methods:get, isCancelled, isDone
        super.afterExecute(r, t);
         
        if (r instanceof FutureTask) {
            FutureTask task = (FutureTask)r;
            try { 
                if (task.isDone() && !task.isCancelled()) {
                    task.get();
                } 
            } catch (InterruptedException e) {
                // do nothing here. let code which is interested  
                // in the result of the task deal with this 
            } catch (ExecutionException e) {
                Throwable badStuff = e.getCause();
                if (badStuff instanceof RuntimeException || badStuff instanceof Error) {
                    Thread currThread = Thread.currentThread();
                    Thread.UncaughtExceptionHandler handler = currThread.getUncaughtExceptionHandler();
                     
                    // should not be null 
                    if (handler != null) {
                        handler.uncaughtException(currThread, badStuff);    
6
CodeRank
This code example shows how to use the following methods:get, isCancelled, isDone
        } 
 
        @Override 
        public boolean isDone() 
        { 
            return task.isDone() || task.isCancelled();
        } 
 
        public boolean isFailed() 
        { 
            if (!isDone()) { 
                return false; 
            } 
 
            try { 
                task.get();
            } 
            catch (Throwable ignored) {
                return true; 
            } 
            return false; 
5
CodeRank
This code example shows how to use the following methods:isCancelled
 
        return future.cancel(mayInterruptIfRunning);
    } 
     
    public boolean isCancelled(){ 
        return future == null ? false : future.isCancelled();
    } 
 
    /** 
     * @throws Exception, captured on passed to onException() if present. 
     */ 
    protected void onPreExecute() throws Exception {}
 
    /** 
     * @param t the result of {@link #call()} 
     * @throws Exception, captured on passed to onException() if present. 
     */ 
    @SuppressWarnings({"UnusedDeclaration"}) 
    protected void onSuccess( ResultT t ) throws Exception {}
 
5
CodeRank
This code example shows how to use the following methods:isCancelled
     * @return <tt>true</tt> if task was cancelled before it completed 
     * 
     * @see #cancel(boolean) 
     */ 
    public final boolean isCancelled() { 
        return mFuture.isCancelled();
    } 
 
    /** 
     * Attempts to cancel execution of this task.  This attempt will 
     * fail if the task has already completed, already been cancelled, 
     * or could not be cancelled for some other reason. If successful, 
     * and this task has not started when <tt>cancel</tt> is called, 
     * this task should never run.  If the task has already started, 
     * then the <tt>mayInterruptIfRunning</tt> parameter determines 
     * whether the thread executing this task should be interrupted in 
     * an attempt to stop the task. 
     * 
     * @param mayInterruptIfRunning <tt>true</tt> if the thread executing this 
     *        task should be interrupted; otherwise, in-progress tasks are allowed 
3
CodeRank
This code example shows how to use the following methods:isCancelled
	 *  
	 * @see #cancel(boolean) 
	 */ 
	public final boolean isCancelled() 
	{ 
		return mFuture.isCancelled();
	} 
 
	/** 
	 * <p> 
	 * Attempts to cancel execution of this task. This attempt will fail if the 
	 * task has already completed, already been cancelled, or could not be 
	 * cancelled for some other reason. If successful, and this task has not 
	 * started when <tt>cancel</tt> is called, this task should never run. If 
	 * the task has already started, then the <tt>mayInterruptIfRunning</tt> 
	 * parameter determines whether the thread executing this task should be 
	 * interrupted in an attempt to stop the task. 
	 * </p> 
	 *  
	 * <p> 
3
CodeRank
This code example shows how to use the following methods:isCancelled
     * @return <tt>true</tt> if task was cancelled before it completed 
     * 
     * @see #cancel(boolean) 
     */ 
    public final boolean isCancelled() { 
        return mFuture.isCancelled();
    } 
 
    /** 
     * <p>Attempts to cancel execution of this task.  This attempt will 
     * fail if the task has already completed, already been cancelled, 
     * or could not be cancelled for some other reason. If successful, 
     * and this task has not started when <tt>cancel</tt> is called, 
     * this task should never run. If the task has already started, 
     * then the <tt>mayInterruptIfRunning</tt> parameter determines 
     * whether the thread executing this task should be interrupted in 
     * an attempt to stop the task.</p> 
     * 
     * <p>Calling this method will result in {@link #onCancelled(Object)} being 
     * invoked on the UI thread after {@link #doInBackground(Object[])} 
3
CodeRank
This code example shows how to use the following methods:isCancelled
     * @return <tt>true</tt> if task was cancelled before it completed 
     * 
     * @see #cancel(boolean) 
     */ 
    public final boolean isCancelled() { 
        return mFuture.isCancelled();
    } 
 
    /** 
     * Attempts to cancel execution of this task.  This attempt will 
     * fail if the task has already completed, already been cancelled, 
     * or could not be cancelled for some other reason. If successful, 
     * and this task has not started when <tt>cancel</tt> is called, 
     * this task should never run.  If the task has already started, 
     * then the <tt>mayInterruptIfRunning</tt> parameter determines 
     * whether the thread executing this task should be interrupted in 
     * an attempt to stop the task. 
     * 
     * @param mayInterruptIfRunning <tt>true</tt> if the thread executing this 
     *        task should be interrupted; otherwise, in-progress tasks are allowed 
5
CodeRank
This code example shows how to use the following methods:isCancelled
     * @return <tt>true</tt> if task was cancelled before it completed 
     * 
     * @see #cancel(boolean) 
     */ 
    public final boolean isCancelled() { 
        return mFuture.isCancelled();
    } 
 
    /** 
     * <p>Attempts to cancel execution of this task.  This attempt will 
     * fail if the task has already completed, already been cancelled, 
     * or could not be cancelled for some other reason. If successful, 
     * and this task has not started when <tt>cancel</tt> is called, 
     * this task should never run. If the task has already started, 
     * then the <tt>mayInterruptIfRunning</tt> parameter determines 
     * whether the thread executing this task should be interrupted in 
     * an attempt to stop the task.</p> 
     *  
     * <p>Calling this method will result in {@link #onCancelled(Object)} being 
     * invoked on the UI thread after {@link #doInBackground(Object[])} 
3
CodeRank
This code example shows how to use the following methods:isCancelled
     * @return <tt>true</tt> if task was cancelled before it completed 
     * 
     * @see #cancel(boolean) 
     */ 
    public final boolean isCancelled() { 
        return mFuture.isCancelled();
    } 
 
    /** 
     * Attempts to cancel execution of this task.  This attempt will 
     * fail if the task has already completed, already been cancelled, 
     * or could not be cancelled for some other reason. If successful, 
     * and this task has not started when <tt>cancel</tt> is called, 
     * this task should never run.  If the task has already started, 
     * then the <tt>mayInterruptIfRunning</tt> parameter determines 
     * whether the thread executing this task should be interrupted in 
     * an attempt to stop the task. 
     * 
     * @param mayInterruptIfRunning <tt>true</tt> if the thread executing this 
     *        task should be interrupted; otherwise, in-progress tasks are allowed 
4
CodeRank
This code example shows how to use the following methods:isCancelled
	 * @return <tt>true</tt> if task was cancelled before it completed 
	 *  
	 * @see #cancel(boolean) 
	 */ 
	public final boolean isCancelled() { 
		return mFuture.isCancelled();
	} 
 
	/** 
	 * Attempts to cancel execution of this task. This attempt will fail if the 
	 * task has already completed, already been cancelled, or could not be 
	 * cancelled for some other reason. If successful, and this task has not 
	 * started when <tt>cancel</tt> is called, this task should never run. If 
	 * the task has already started, then the <tt>mayInterruptIfRunning</tt> 
	 * parameter determines whether the thread executing this task should be 
	 * interrupted in an attempt to stop the task. 
	 *  
	 * @param mayInterruptIfRunning 
	 *            <tt>true</tt> if the thread executing this task should be 
	 *            interrupted; otherwise, in-progress tasks are allowed to 
3
CodeRank
isCancelled Method Overview
Returns true if this task was cancelled before it completed normally.
See Code Examples for other Java 8 FutureTask Methods: