I would like to ask you HOW (or IF) you can reduce the size of the Spring memory area.
I created a simple helloworld application to demonstrate the problem. There are only two classes and the context.xml file:
Main - class with the main methodTest - a class used to simulate some "work" (printig Hello in an infinite loop)
context.xml contains only this:
<context:component-scan base-package="mypackage" />
The test class contains only the init method, 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 scripts, and in both of them the Main method contains only one line.
In the first scenario, the main method does this: (new Test()).init(); The application works without Spring and consumes only aprox. 8 MB of RAM.
In the second scenario, the main method contains the following: new ClassPathXmlApplicationContext(new String[]{"spring/context.xml"}); Thus, the application is initialized by the Spring container and consumes aprox. 45 MB RAM!
Is there a way to reduce (at best, completely get rid of) this extra memory? So far I have not been able to find a suitable solution.
I do not mind if additional memory consumption is added during startup - this is fine, but after that I need our application to reduce it.
(The story behind this question is a little more complicated, but for me this is now the main problem.)
thanks
java spring ram
Kousalik
source share