LPS-44902 Stop and release the resources after everything has been finished

Updated @migue 's changes resolving conflicts (See https://github.com/brianchandotcom/liferay-portal/pull/17143)