Re: Having an issue with Sun VM + Hibernate + Oracle
Joseph Cavanagh wrote:
Currently we are having an issue with Oracle running out of cursors
(Max cursors are set to 1500, with some other apps utilizing a small
percentage of those). We are using hibernate within our java code.
The cursor error happens after about 50-60 minutes of the application
running and processing. I've noticed that heap size (average) and
classes loaded continues to climb until the app errors and is no
longer able to process. At this point I'm thinking that it may be
something to do with classes are never garbage collected and are just
tossed in either permGen or oldGen. Would this cause an error with
cursors? Is it possible that a class that isn't unloaded is causing
hibernate to not clear a cursor? I'm not on the development end so
I'm not 100% familiar with their code.
It's not class unloading that affects cursors, it's Hibernate sessions or JPA
entity managers depending on which mechanism you're using. Entity managers
are by far the easier to use.
Look up "Resource Acquisition is Initialization" (RAII) for Java, a collection
of idioms and practices that let you manage resource lifetime, such as
connections to a database, via object lifetime and other means. The 'try
{...} finally {...}' construct is your friend.
I am working with this now for a Hibernate-based project, using entity
managers. If you don't close the entity managers, you risk not closing the
connections until they time out, which could be quite a while. If you create
lots of entity managers without closing them, over time you use up this
precious commodity. The same with sessions.
The general rule with resources is to be certain that you release them. You
release memory by ensuring that object references go away. You release
connections by closing them. You tie the two together with 'try {...} finally
{...}' and, occasionally and with great finesse, finalizers.
I have no idea why your loaded classes increase over time. Perhaps your
objects are creating anonymous classes a lot?
--
Lew