rework shutdown for jruby compatibility

jruby is no longer happy with selecting on the same socket in multiple
threads (failing with "ConcurrencyError: can not set IO blocking after
select; concurrent select detected?"), this means we can no longer use
a pipe to wake up threads waiting on IO when we're shutting down.

jruby also delays exceptions raised from another thread till certain
'checkpoint' methods, which don't include select, so we can't use that

instead make select calls wakeup every now and again to check if we're
shutting down