Hi,
This is the scene.
Session sess = getSessionFactory().getCurrentSession(); txn = sess.beginTransaction();
int i = 0; for(MyRecord record: records) { sess.persist(); if(i++ % 512 == 0) { sess.flush(); sess.clear(); } }
sess.commit();
This code trying to call flush every 512 rows. However it gets called even for i =0. (This is bug in code :) )
So now lets say there are 513 records. In this case flush and clear will be called twice. First when i == 0 and later when i == 512. And later it calls commit.
So problem now is this second flush call takes 10 mins to complete. This is happening only for second call. Meaning lets say there are 2000 records. So created batches are based on index values will be : 0-0, 1-512, 513-1025 , 1026.... and so on. So there will be i think 4 flush() calls. Every batch gets flushed in 3-4 seconds. But this second call to flush for 1-512 batch takes 10 mins to complete.
And it is not just flush() actually. When second call happens to be on commit(), it stucks. Meaning for records say 400. For i = 0, it will call flush and clear. So for remaining 399 it directly calls commit() after getting out of the loop. So on this commit() also it stucks for 10 mins. (i.e. only when it happens to be just after first flush() call)
My table is ALLPAGE locked. It has a primary key. It has at max 10000 records. This is plain JDBC application. Database is sybase. My Query cache: disabled, second level cache is enabled, Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory, hibernate.current_session_context_class is thread, Session factory is local host non-jta. table data gets deleted once nightly.
If you have any suggestion, hint on why this second flush() or (commit() ) call stuck for 10 mins always, will be appreciated.
thanks
|