Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 needed to handle the request. Due to this delay, some clients time out. Although it is possible to increase the time-out delay in the client, I'd like to minimize the impact that class loading has on the application's responsiveness.

How would you preload Java class files so that when the application's .jar file is first run class loading does not introduce a delay on the first call?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
940 views
Welcome To Ask or Share your Answers For Others

1 Answer

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...
   }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...