Updated Code to Shutdown the Threads/VM Gracefully.