0

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 ?

0

1 Answer 1

1

In Java, classes are initialized the first time they are loaded. It is your first request that causes the classes to load.

Maybe this will help.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I agree with you on the Java initialization problem. further your referral link should be very close to my problem, I will check soon. Thanks very much !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.