Q:

Initialization and release of global resources with spring

In our applications we usually have some resources (utilities) that are used application wide, for example that might be an apache HttpClient, or in my case ConcurrencyUtils which is an utility class that manages all the thread pools for cpu intensive and io tasks (adds some schedulers for reactive streams etc... a lot of custom stuff). 
Now when I initialize my context trough spring i have to do something unnatural like this (in order to initialize and destroy static resource)

Note that ConcurrencyUtil is just a fake class with no use, we never use it but we use static methods of ConcurrencyUtils and this class only ensures that init and destroy are called (and i'm not sure how to ensure that destroy is called after all beans were destroyed)...

So how do we run a piece of code before spring context creates any bean and after spring context has released all its beans (and is about to be reclaimable itself)? 
Whats the right way to initialize and release static resource with spring? 

A:

This probably works fine.  You could also put this in one class that is in the classpath that gets scanned for beans:
@Configuration
public class ConcurrencyConfig {

    @PostConstruct
    public void init(){
        ConcurrencyUtil.init();
    }

    @PreDestroy
    public void destroy(){
        ConcurrencyUtil.destroy();
    }
}

which looks a bit nicer I guess.