How to avoid the execution of an idempotent code?
<p>I have a class which has an init method which does initialization of the member variables.So I wanted the execution of that code to be run only once for any number execution of that class. So how to go about that?</p>

<p>please let me know if the question is not clear.</p>

<p>EDIT:</p>

<p>Actually I have some legacy code with thousands of classes having the big init methods. which does the initialization(with all static values) of the member variables. </p>

<p>And say suppose In a main method if I have a reference to any of these class. and I run the main method for 100 times then all 100 times it executes the same method which is a performance hit. So i thought of having the member variables as static and do the initialization only once for any number of execution. but I thought it will lead to a OutOfMemory as all the objects for those thousands of classes will remain in jvm till it dies.</p>

<p>Hope it is clear now.</p>

<p>Thanks.</p>
