The Source for Java Technology Collaboration

Home » java.net Forums » GlassFish » GlassFish

Thread: Forcing commit and em.flush does not seem to do it

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 4 - Last Post: Mar 5, 2008 10:48 AM by: jaxent
jaxent

Posts: 4
Forcing commit and em.flush does not seem to do it
Posted: Mar 4, 2008 10:41 AM
  Click to reply to this thread Reply

I am running out of memory and cpu doing mass updates on my application. At this point it is only happening on my dev machine, but the application will be adding more data so I fear I will see it in staging or production in the future if I don't handle it now. I am using Netbeans 6.0, glassfish v2, toplink, and postgres.

The basic question is how do I force a stateless session bean to commit? I have placed em.flush statements at points where I would like to have it commit all the statements that have been run up to that point, but it does not seem to do it. I have debug loggin on for JPA and I can see the queries going to the DB, nothing happens when em.flush() is called.

jaxent

Posts: 4
Re: Forcing commit and em.flush does not seem to do it
Posted: Mar 4, 2008 11:49 AM   in response to: jaxent
  Click to reply to this thread Reply

Never mind. I just had to call em.setFlushMode(FlushModeType.COMMIT);

jaxent

Posts: 4
Re: Forcing commit and em.flush does not seem to do it
Posted: Mar 4, 2008 2:32 PM   in response to: jaxent
  Click to reply to this thread Reply

It turns out that did not work.

whartung

Posts: 634
Re: Forcing commit and em.flush does not seem to do it
Posted: Mar 4, 2008 8:42 PM   in response to: jaxent
  Click to reply to this thread Reply

No, that wouldn't work.

While all of your work is creating actual DB calls, the problem is that your transaction is not commiting. So all of those objects that you are creating are staying alive, and in the managed state. All flushing does is ensure that they're written to the DB, but it does not release the managed objects.

You might trying makes calls to em.flush(), then followed by a call em.clear(), which is supposed to reset all of the managed entities, and make them unmanaged (and, in theory, available for GC).

If that doesn't work, then you may want to try and break your transaction up in to batches, and commit the transaction at a regular interval.

I'm curious if the em.clear() during a transaction actually works though, so it would be interesting if you tried that and reported back.

jaxent

Posts: 4
Re: Forcing commit and em.flush does not seem to do it
Posted: Mar 5, 2008 10:48 AM   in response to: whartung
  Click to reply to this thread Reply

That seemed to do the trick.

What I don't get is why it would have held the references with out the clear. In this configuration, I was calling the remote interface on a stateless session bean from my timer bean. I would expect that when the call to the stateless bean completed it would serialize the object and then the stateless bean would be done with it and mark it for gc. Why would a remote bean not tell the entity manager to clear? I can understand it if I used the local interface. Would it have cleared if I called the remote interface from another container?




 XML java.net RSS