Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8173939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:19:29+00:00 2026-06-06T22:19:29+00:00

import org.joda.time.LocalDate; public class Test { public static void main(String[] args) { long time=System.currentTimeMillis();

  • 0
import org.joda.time.LocalDate;

public class Test {
    public static void main(String[] args) {
        long time=System.currentTimeMillis();
        new LocalDate(2000,1, 1);
        System.out.println(System.currentTimeMillis()-time);
        time=System.currentTimeMillis();
        new LocalDate(2000,1, 1);
        System.out.println(System.currentTimeMillis()-time);
    }
}

The first call to new LocalDate takes 110ms.
The second call takes 0ms.

Firstly how do I run all the static initializers for a given class?
Secondly, is there a way to do this for all classes my application references in advance?

My application is very latency sensitive.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:19:31+00:00Added an answer on June 6, 2026 at 10:19 pm

    You can get a list of classes loaded with -XX:+TraceClassLoading and save this to a file.
    You can then use Class.forName() to ensure all these classes have loaded.

    This will load every class and ensure their static blocks have been loaded.

    However for latency sentive code, you really need to ensure it has been compiled by warming it up (i.e. calling it enough times to trigger compilation) This can reduce latency by a further factor of 10 or more.


    If you run

    public class CallStatic {
        public static void main(String... args) throws ClassNotFoundException {
            Class.forName("Static");
        }
    }
    
    class Static {
        static {
            System.out.println("static block run");
        }
    }
    

    prints

    static block run
    

    Trying to create an instance won’t load the class more. It may load the default constructor if it has one, but that will only help if thats the one you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please, take a look at this example: import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class Test
Is there a way say, import org.junit.Test; public interface ITest { @Test public void
import org.apache.tools.ant.Project object HelloWorld { def main(args: Array[String]) { println(Hello, world!) } } I
import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPReply; import org.apache.commons.net.ftp.FTPFile; import java.io.*; public class FTPUpload{ public static boolean
I have a class DurationFormatter as below: import java.util.Date; import org.joda.time.DateTime; import org.joda.time.Period; import
import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapPrimitive; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.AndroidHttpTransport; import org.ksoap2.transport.HttpTransportSE; public class
I write the following class: import org.apache.commons.jexl2.*; public class NelderMead { // контсанты private
import org.json.simple.JSONArray; import org.json.simple.JSONAware; import org.json.simple.JSONObject; import org.json.simple.JSONValue; public class JsonTest implements JSONAware {
I have a class that extends DataRow : import org.jdesktop.dataset.DataRow; public class MainDataRow extends
I'm running the following code: import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; public class WorkspaceTest { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.