BadriNath Ojha

Greenhorn
+ Follow
since Aug 05, 2012
BadriNath likes ...
Java
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by BadriNath Ojha

Jayesh A Lalwani wrote:Beans are kept in memory as long as they are in scope. If the are singleton scoped they will stay in memory as long as the application context is in memory. If you don't want to keep the bean in memory, you should use a differrent scope. Prototype scope will create and destroy the bean everytime you request it from app context. The lifetime of session scoped beans will be limited to the web session. THe lifetime of request scoped beans will be limited to the HTTP request.

If you want a differrent mechanism for controlling the lifetime of beans, you will have to define a custom scope.

Lazy Loading pattern doesn;t save memory for objects that are always going to be used. Lazy Loading pattern prevents objects that are seldom used from loading at startup. If you want objects to die off after they have not been used for a while, you need to have some sort of Pooling mechanism that destroys objects that are not used recently.



Is saving the memory at startup, the sole purpose of lazily instantiated beans? What will happen if those beans are loaded at startup?
7 years ago
We declare the beans to be lazily initialized in the application context xml. The need is to delay the object creation till it is required and no creation if not required for heavy objects to keep as much memory free as possible. The question is suppose once the lazily instantiated bean is accessed then that bean is created and is held in memory, after usage is the instance destroyed implicitly or is kept in memory as long as container lives?
If above is true then what is the benefit of lazy initialized beans as it occupies memory after first access?
7 years ago
I am saving one entity in the database using the session.save(Object obj) method. I have set the auto commit as true in the config file. The ID generator is "native".
The entity is saved properly.
Wanted to understand the save() behavior when the ID generator is changed to assigned. In case it is assigned it does not inserts the entity.
Please explain with reference to persistence context of session object, and database.
Also, why do we need flush(), if save() saves data in the DB and I could see that after flush the size of persistence context object does not changes, then what is the reason for it.
Another point, reading http://docs.jboss.org/hibernate/orm/3.5/reference/en/html/transactions.html, It mentions that data base transactions are never optional. But in case the ID generator is native and after I flush the session, the changes are reflected in the DB. I am using mySql as DB. Is it that save internally opens a DB transaction of mySql in case ID is native.
Winston, I was going thru the LinkedHashMap impelmentation, there they have done the same thing as above and they are not getting NPE. This was what confused me.
7 years ago
By Object creation I mean allocation of memory in heap.
Why this Question in my mind is that we can instantiate the subclass variables using the super class constructor and call the overriden method in sub class to set the orivate variable value. Since the super is setting the values and the sub class constructor has not started so object is not there but the variables are initialized.
7 years ago
I am curious to know as which event occurs first initilaization of variables and then object creation or creation of object and then initialization of instance variables.

7 years ago
Thanks Joanne, It helped me a lot. I was somehow confused about the implementation in 1.6 but 1.7 implementation is very clear.
7 years ago
I was going through the code for adding elements in the LinkedList and was unable to match the theory of LinkedList with the code. Everytime a new element is added the Object and header is sent to addBefore() method and the header reference values are changed. But again I am unable to understand how it is able to point to next and previous element.
Please explain in simple words.

private transient Entry<E> header = new Entry<E>(null, null, null);

public boolean add(E e) {
addBefore(e, header);
return true;
}

CALLS

private Entry<E> addBefore(E e, Entry<E> entry) {
Entry<E> newEntry = new Entry<E>(e, entry, entry.previous);
newEntry.previous.next = newEntry;
newEntry.next.previous = newEntry;
size++;
modCount++;
return newEntry;
}

Thanks in advance...
7 years ago
Thanks to all you guys. Your answers were really helpful.
7 years ago
The Iteratior provides the functionality of traversing and removal which we can achieve through normal for loop and remove() of the data structure.
Then, why do we need Iterator explicitly and as an inner class?
Thanks in advance.
7 years ago
I am a newbie for web hosting. I wanted to host my first website on shared tomcat on windows but always need to append the war file name with my domain name as domain.com/war-file-name.
I want to get my pages only by entering domain.com.
Please let me know how to achieve this.

Thanks in advance.
7 years ago
I wanted to know what happens when notify and notifyall is called on an object.
I read from some blog that when notify() is called only one thread out of many which called the wait() on the object is made awake from WAITING state and made RUNNABLE directly and when notifyall() is called then all the threads which called wait() are made awake but only one choosen by JVM scheduler and shifted to RUNNABLE state and others in BLOCKED state and not in WAITING state.
Please let me know.