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

public class Main {

static enum Some {
    FOO;
}

static abstract class Foo {
    public abstract Some getType();
}

static class FooExt extends Foo {
    @Override
    public Some getType() {
        return Some.FOO;
    }
}

public static void main(String[] args) {

    ExecutorService service = Executors.newFixedThreadPool(2);
    final CountDownLatch start = new CountDownLatch(1);
    Future<Integer> f1 = service.submit(new Callable<Integer>() {
        @Override
        public Integer call() {
            try {
                start.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Task started...");
            int a = 0;
            Foo foo = new FooExt();
            while (!Thread.currentThread().isInterrupted()) {
                if (foo instanceof FooExt) {
                    a++;
                }
            }
            System.out.println("Task ended...");
            return a;
        }
    });

    Future<Integer> f2 = service.submit(new Callable<Integer>() {
        @Override
        public Integer call() {
            try {
                start.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Task started...");
            int a = 0;
            Foo foo = new FooExt();
            while (!Thread.currentThread().isInterrupted()) {
                if (foo.getType() == Some.FOO) {
                    a++;
                }
            }
            System.out.println("Task ended...");
            return a;
        }
    });
    start.countDown();
    try {
        Thread.sleep(100);
    } catch (InterruptedException e) {
    }
    service.shutdownNow();
    System.out.println("service is shutdowned...");
    try {
        System.out.println("instanceof: "+f1.get());
        System.out.println("enum: "+f2.get());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

}