Why can't i instantiate ThreadPoolExecutor with BlockingQueue<Callable>; why only BlockingQueue<Runnable>?

java, java-5, threadpoolexecutor

Solution

You can submit `Callables`, but they get wrapped internally as `Runnables` (actually `FutureTasks`, which implement `Runnable`). `shutDownNow()` is only going to return `Runnables`, just like it says on the tin.

If you want to get the list of `Callables` that haven't been run, you'll need to keep track of them yourself somehow (e.g., keep a list of them and make them responsible for removing themselves from the list when they're called.)

Problem

My understanding is that callable was added in 1.5 and the runnable interface was kept as-is to prevent the world from ending. Why can't I instantiate a `ThreadPoolExecutor``(core, max, tu, unit, new BlockingQueue<Callable>())` - why does the queue necessarily take runnable only? Internally, if i were to submit, invokeAll, invokeAny callables, this should be fine right? Also, would `shutDownNow()` return a list of callables?

Original source