I would like to ask you HOW (or IF) is possible to reduce Spring framework's RAM footprint.
I created a simple helloworld app for demonstrating the issue. There are only two classes and context.xml file:
Main
- class with main methodTest
- class used for simulating some "work" (printig Hello in endless loop)
context.xml
contains only this:
<context:component-scan base-package="mypackage" />
Test class contains only metod called init
, called after construction:
@Component
public class Test{
@PostConstruct
public void init() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
while (true) {
System.out.println("Hello " + Thread.currentThread().getName());
Thread.sleep(500);
}
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
});
t.start();
}
}
I prepared two scenarios and in both of them main
method contains only one line.
In first scenario main method does this: (new Test()).init();
App works without Spring and consumes only aprox. 8MB of RAM.
In second scenario main method contains following: new ClassPathXmlApplicationContext(new String[]{"spring/context.xml"});
So the app is initialized throug Spring container and consumes aprox. 45MB of RAM !
Is there any way how to reduce (in best case completely get rid of) this extra memory ? So far I wasn't able to find any fitting solution.
I don't mind if there is the extra memory consumption on startup - this is perfectly fine, but after that, I need our app to reduce it.
(The story behind this question is a bit more complicated, but this is for me now the core problem.)
Thank you