Preloading java classes/libraries at jar startup?

后端 未结 3 833
刺人心
刺人心 2020-11-29 12:09

A time-out occurs during the first RPC call to a server yet subsequest requests succeed. The server times-out on the response because upon first call it loads the libraries

3条回答
  •  迷失自我
    2020-11-29 13:13

    You could run a load before the server becomes live. You haven't specified how you're loading the server, the classes, and what the environment is, but you can take advantage of the fact that a class static initializer will run when the class is loaded. So, if you're running from a "main" method, your class could look something like this

    public class Foo {
    
       static {
         //this will be run when the class is loaded
         try { Class.forName("fully.qualified.class.name.that.i.want.to.Load"); }
         catch ...
       }
    
       public static void main (string args[])
       {
        //run my server...
       }
    }
    

提交回复
热议问题