[KARAF-3325] Add a workaround to avoid sudden shutdown

This change is a copy of the change that fixes the same issue of Tomcat.

https://github.com/apache/tomcat70/commit/4b1818de6f2d79c8b4e0362830cbe10f23685a3a#diff-4ff8e67f5558cd457dc3fcbe7c7581a9R47