Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S closing a stream

 
Jakub Drzazga
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have doubts with closing a stream to �db-2x2.db�. Is it better to open it once at the beginning of the program and close it at the end? Or is it better to open and close a stream every time when access to a file is necessary.
If I decide to open it only once is it appropriate to use finalize() method to close the stream (it would be executed by garbage collector)?
Please help.
 
Alain Dickson
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jakub,
Stream is IO, which is a intensive on system resources. Keeping the stream open for so long would be taken as a bad design.
The user may sit for an hour and keep the application open, waiting for customers.
Closing and opening stream time and agin will not hurt so much as keeping it open.

Alain
SCJA, SCJP6
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Champ, take a look at this thread. I think it might be helpful.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic