When you have a method that always return the same object from the session using the getter method of session.
Example: public Long getSession()
{
return session.getObject("key");
}
You want the same method to be called multiple times in the code. Is it fine to first call the method once and hold the result in a variable at the starting of the code, and later reuse it (or) call the method multiple times ?
To me calling the method multiple times would be a good thing, because, that method is not doing anything, except that, it returns the same object from the session by calling the getter of the session.
But on the other hand, if you declare a variable to hold the object, and reuse the variable everywhere, thoughout the code, it may be a bit expensive as declaring a variable itself will allocate certain space in the memory, which I think is un-necessary.
Could anybody suggest on this...and also how to
test this...? I tried with Runtime.getRuntime().freeMemory(), but it always return me the same value.