• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.io.IOException: Bad file descriptor

 
Steve Taiwan
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using JBuilder to develop my SCJD project.
And I add finalize method in Data.java to close RandomAccessFile object.
However, when I test my code by using JUnit in JBuilder, the finalize mehtod is called to close
db file before some test methods in my JUnit code. So it always gives me :

java.io.IOException: Bad file descriptor

Dose anyone know how to prevent from calling finalize method before running JUnit Code???
Thanks.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finalize is called when the garbage collector is about to reclaim the memory. So you JUnit class must still be going, after you already set the object to null, or it went out of scope. The garbage collector works when it wants to, so you really can't time something like that. You can keep the instance going in your JUnit till that ends, then you won't have that problem.

Mark
 
Steve Taiwan
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Mark.

Thank you for the reply.
I gave up the finalize method but keep shutdown hook.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic