Question: So I need to do a query based on the results of another query.   
Is there a way for me to set the result of a query to a variable so I can use the result of that in another query?

Example:  

{original query} --->

```
SELECT
tablea.number

FROM tablea

INNER JOIN tableb

ON tablea.name = tableb.name

WHERE tableb.zip = '11111'

```

Now I want to use this result to then do another query:

```
SELECT *

FROM tablea

WHERE number = (results of last query)

```

I think theres a way to set the first query to a variable so that that way the second one can just use the result, just not sure how. Thanks.

Answer: 
What you are doing is [specifically prohibited](http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#addShutdownHook%28java.lang.Thread%29):

> 
> Shutdown hooks should also finish their work quickly.
> 
> 
> 

Joining random threads cannot be described as 'quick'.

Obviously those threads should close their *own* streams when they exit. If they don't exit, how will calling `join()` accomplish anything?
Use executors and don't use join or manually create threads. 

When using an executor and the other stuff in java.util.concurrent, you can simply call shutdown and wait for it to terminate, specify a timeout, etc. Much more robust. If you are using java 1.7, use try with resources to close your streams as well. That way, you don't have much cleanup work to do beyond shutting down your executor. If not, use a finally block. Never call close anywhere else than from a finally block.