I am creating a REST service with Jersey. Some resources (like some global Maps, files) should be loaded before the first request arrives (because loading this resources need 20 secs). So I create some static fields (attributes) to hold these resources, because I believe they should be initialized when I start this REST service.
However, I found one strange problem that static resources will be loaded only when I send the first request. So for the first request, it always takes more than 20s to get response, while later requests are much faster (since resources have been loaded).
Could anyone explain me why Java doesn't initialize these static fields before any request ?