Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

After deleting 14 records, application hanging

 
Dhananjay Inamdar
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

As a part of my enterprise application, I have one functionality, where code selects all of the records from one table and process them one by one. If the record gets processed succesfully then application deletes this record, if not, then set the 'Processed' flag to 'NO'.

When ever I am executing this piece of code with 300 records in the table, application select all of the records and starts processing them one by one. First 14 records getting processed properly and as per the flow records are getting deleted also from the table.

When it crosses 14th record then on 15th application processed the record but after that when it tries to delete this record application just hangs. I am not sure why application is not able to delete 15th record.

If you stop the application and restart it then again application will delete first 14 records and will stop on 15th record.

Code of my delete method is as follows

<blockquote>code:
<pre name="code" class="core">
public void delete( BatchEntry batchEntry )
{
Connection _con = null;
Statement _st = null;
try
{
_con = getHibernateSession().connection();
_st = _con.createStatement();
_st.executeQuery( "Delete from BATCH_ENTRIES where ID = " + batchEntry.getId() );
_con.commit();
}
catch ( SQLException _se )
{
try
{
_con.rollback();
}
catch ( SQLException se )
{
m_log.error( "Could not rollback DB connection", se );
}
m_log.error( "SQLException while deleting record from BATCH_ENTRIES, exception is : ", _se );
throw new FitnessRuntimeException( _se );
}
finally
{
close( _st );
close( _con );
}
}

</pre>
</blockquote>


Please do let me know if you need any more information.

Thanks
[ July 16, 2008: Message edited by: Mark Spritzler ]
 
Dhananjay Inamdar
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to add more information, on 15th time application is hanging on the following line

_st = _con.createStatement();

Of this Delete() method.

Please help me solving this problem.

Thanks in advance!
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am confused, are you opening a statement for each delete of a record? Doesn't that seem overkill. Couldn't you come up with just one statement that deletes everything that you need in one time.

Are you sure all your connections/statements are closing, because I am assuming here that you are just running out of connections/statements because it is configured to only give you so many, and since they aren't being released, then it just waits for one.

Mark
 
Dhananjay Inamdar
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,

Thanks for the reply!

I cann't create a statement which will delete all the required records in one shot, since this is how the nature of the application. I have to select all the records from the table and process each record one-by-one. If process is succesull then delete that single record.

BUT, after reading your reply I did review my code and find out that I am closing statement and connection but not Hibernate Session. So I did close the Hibernate Session also after connection and that thing solved my problem.

Now application is not stopping after 14th record and deleting all the processed records.

Thanks once again!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic