import java.util.Scanner;
import java.util.concurrent.*; 
public class TestFutureCancelTask {

	public static void main(String[] args) throws Exception { 
		final ScheduledExecutorService e = Executors.newSingleThreadScheduledExecutor(); 
		Future<?> f = e.submit(new Runnable() { 
			@Override 
			public void run() { 
				System.out.println("task started"); 
				try { 
					Thread.sleep(100); 
					Scanner scan = new Scanner(System.in);
					System.out.println(scan.nextLine());
									
				} catch (Exception e) { 
					System.out.println(e);
				} 
				System.out.println("task completed"); 
			} 
		}); 
		Thread.sleep(10); 
		boolean b = f.cancel(false); 
		System.out.println("cancel() returned " + b); 
		try { 
			f.get(); 
			System.out.println("get() returned normally"); 
		} catch (Throwable t) { 
			System.out.println("get() threw " + t); 
			
		} 
		e.shutdownNow(); 
	} 
} 