JCBC-509, JCBC-514: Make sure the environment is shut down when not shared.

Change-Id: Ia793d0a00b8e1e311c4b811227ee9af8c39b4c57
Reviewed-on: http://review.couchbase.org/40795
Reviewed-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>