Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class Main {
    public static void main(String[] args) {
        Callable<Object> badTask = () -> {
            throw new RuntimeException("Throwing exception from task execution...");
        };
        ExecutorService exec = Executors.newSingleThreadExecutor();
        Future submittedTask = exec.submit(badTask);
        try {
            Object result = submittedTask.get();
        } catch (ExecutionException e) {
            System.out.println(e.getMessage());
            System.out.println(e.getCause().getMessage());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        exec.shutdown();
    }
}