Skip to main content

Posts

Showing posts from April, 2017

Java Custom ClassLoader

Problem I want my previously written java application to be run multiple times by a shell script with calculated parameters. However, target platforms may not contain bash. Thus I decied to write another class which acts like a bash script file and launch my application with generated parameters. My application has static variables and static classes. Before every launch I want the state information be cleared. But since I work in the same JVM, static objects will not be removed. It comes out using static fileds and initializers may not be a good approach. There should be a way to solve this.  The solution is to use a custom classloader. Classloader will load all classes. At the end of the execution, the classloader and all the classes loaded will be garbage collected. At next execution, all classes will be reloaded. Solution : Custom Class Loader Class loaders can be considered a container to launch an application. Servlet containers like Tomcat uses a custom classloade