Fix race condition during shutdown causing a NPE.

From the getThreadGroup() Javadoc:
	Returns the thread group to which this thread belongs.
	This method returns null if this thread has died (been stopped).