Home > Back-end > Java custom class loading new highly loaded classes will be used?
Java custom class loading new highly loaded classes will be used?
Time:11-22
Under the general logic of this code is that in the main method has two parts, the first part is to start a thread, the thread will be after 2 hours, using custom this reload MyService this class, the second part is in the main thread, have an infinite loop, will continue to call the method that MyService,
If after 1 hour, we modified the MyService. The class of the execute method,
Then in the second hour, we will custom this initiative to load the modified class files, after loaded, we in the main thread, in the new MyService, using the new MyService?
public class App { Public static void main (String [] args) { Thread t=new Thread (() - & gt; { Try { TimeUnit. HOURS. Sleep (2); {} catch InterruptedException (e) } //after sleep for two hours, using UrlClassloader specified path from the hard disk loading MyService. Class files //UrlClassloader XXX... }); t.start();
//XXXXXXX While (true) { MyService service=new MyService (); Service. The execute (); } } }
CodePudding user response:
Which brother help have a look at? thank you
CodePudding user response:
Has been loaded should not load again. If you want to achieve the effect of heat load, should not so simple to play, according to my understanding, after you success in thermal load, the new new objects are not important, before the new object will also adopt the method of new loading class area.
Modify the code can refer to the eclipse debug mode can take effect immediately, now spring environment, object is assembled when it is started
CodePudding user response:
URLClassLoader seems to also want to check the bootstrap classload before loading, unless you are to write a, don't do parents, but I estimate is can't use new to this way to create objects, get class reflection should be able to ensure that is not the bootstrap classload loaded
CodePudding user response:
Are not tested well, free play
CodePudding user response:
The same type of loader after class is loaded into the cache as if, according to the name of the class to store the findClass is to find whether the loaded by name, so you two hours after class may not be loaded
CodePudding user response:
I understand is, even if you can use your own class loader loads, this class will not use your App loaded MyService, class loader in the virtual machine + class qualified name global positioning to a class, you change the class loader is equivalent to another class.
For example we deployed in tomcat two identical application, although in some kind of global qualified name (the package name and class name) the same class, but the call won't appear across projects calls, because of the different project class files with different class loader loads