Stopping all Runnable tasks when one is terminated I want to run couple of Runnables. If one is failed, all others' execution should be terminated. Here is my approach. I got idea on this from this question   and this article. 

In my code, I check the runnable which completes its task first among all and evaluate it. If that checking is failed (completionService.take().get()), all remaining executions are cancelled.

    java.util.List&lt;String&gt; tasks = Arrays.asList("1", "2", "3", "4", "5");
    List&lt;Future&gt; futureList = new ArrayList&lt;Future&gt;();
    final ExecutorService pool = Executors.newFixedThreadPool(5);
    final ExecutorCompletionService&lt;String&gt; completionService = new ExecutorCompletionService&lt;&gt;(
            pool);
    for (final String site : tasks) {

        futureList.add(completionService.submit(new Callable&lt;String&gt;() {
            @Override
            public String call() throws Exception {
                int i = Integer.parseInt(site);
                System.out.println("iterating i: " + i);
                if (i == 4) {
                    throw new RuntimeException("Forcd exception");
                }

                if (i % 2 == 0) {
                    try {
                        Thread.sleep(2000); // simply wanted to change the
                                            // execution time...this is for
                                            // 2s and others 5s.
                    } catch (InterruptedException e) {
                        System.err.println("Interrupted sleeping: "
                                + e.getCause());
                    }
                } else {
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {
                        System.err.println("Interrupted sleeping: "
                                + e.getCause());
                    }
                }
                return site;
            }
        }));
    }

    for (Future ft : futureList) {

        if (!futureList.isEmpty()) {
            try {
                System.out.println("future get.");
                String task = completionService.take().get();
            } catch (InterruptedException e) {
                System.err.println("Interuppted here: " + e.getMessage());
                // Thread.currentThread().interrupt();
                break;
            } catch (ExecutionException e) {

                System.out.println("Execution exception " + e.getMessage());
                for (Future future : futureList) {
                    if (!future.isDone()) {
                        System.out.println("Cancelling " + future);
                        future.cancel(true);
                    }
                }

                pool.shutdownNow();
                break;
            }
        }
    }
    pool.shutdownNow();


I want to know whether is this approach is good enough and any one see any problem in above code? I checked it and it does its job for me (i==4, it terminates) for few tests. But not sure whether it makes problems in long run. 

This will run in a server, will this effect on server performance? I don't want to check the first completion runnable task, but if any runnable fails, all remainings should be removed. Sometime my approach will be long and another short solution will be there. Expect your ideas. Thanks.
Your general approach is sound

When your Callable throws, the throw will be propagated out of the Future, you catch it and cancel all remaining futures. I believe it is safe to cancel a completed job so you might not need the !isdone() check. But that's nitpicking.
Then you shutdown your thread pool to clean up.

Your implementation is a bit messy

The loop where you iterate over all the futures seems a bit messy to me. 

For example:

for (Future ft : futureList) {
    if (!futureList.isEmpty()) {


this condition will always be true. And you are never removing from the list (if you were, you would get a ConcurrentModificationException. So the check is wholly redundant.

So you loop over all of the futures in futureList and call take() on your completionService. This doesn't make sense to me, if you're going to call take() use a loop that describes what you want to do better. This is further strengthened by the fact that you never use the ft loop variable.

Maybe something like this:

while(futureList.size() &gt; 0) {
    Future ft = completionService.take();
    futureList.remove(ft);

    try{
        String task = ft.get();
    }catch(InterruptedException e){
        // Interrupted
    }catch(ExecutionException e){
        // Snap, something went wrong in the task! Abort! Abort! Abort!
        for(Future f : futureList){
            f.cancel(true);
        }
        futureList.clear();
    }   
}
pool.shutdownNow();