// with proper changes (component changed to application):
if ((getApplication() != null) && (getApplication().isStarted())) {
try {
try {
// here, we _ensure_ it is shut down properly, since the allowed shutdown seems never invoked?
final TaskService taskService = getApplication().getTaskService();
if (taskService != null) {
taskService.setShutdownAllowed(true);
taskService.shutdownNow();
}
}
finally {
getApplication().stop();
}