• Post Reply Bookmark Topic Watch Topic
  • New Topic

References to OutputStream/Writer  RSS feed

 
Jay Damon
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know I should probably be using a logging mechanism but bear with me (baby steps please).

I am working on a web application that logs page accesses to a mapped Windows drive. This has become somewhat of a bottleneck in the application. My first approach was to spin the logging process off as a thread. However, I have discovered that doing so is still somewhat expensive.

However, I have discovered that by hanging onto the reference to the OutputStream/Writer object and invoking flush() after the write, I can increase performance by a factor of 10 or more. This concerns me though because the object will never be explicitly closed.

The PageLogger class I have written for testing purposes invokes close() in its overridden finalize() method but I'm concerned that is not sufficient.
Is this a reason for concern or is there perhaps some other option I am overlooking?
 
Joseph Kampf
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are using FileOutputStream directly?

I suggest that you try passing your FileOutputStream into the constructor of a BufferedOutputStream, then write to the BufferedOutputStream.

Joe



Originally posted by Jay Damon:
I know I should probably be using a logging mechanism but bear with me (baby steps please).

I am working on a web application that logs page accesses to a mapped Windows drive. This has become somewhat of a bottleneck in the application. My first approach was to spin the logging process off as a thread. However, I have discovered that doing so is still somewhat expensive.

However, I have discovered that by hanging onto the reference to the OutputStream/Writer object and invoking flush() after the write, I can increase performance by a factor of 10 or more. This concerns me though because the object will never be explicitly closed.

The PageLogger class I have written for testing purposes invokes close() in its overridden finalize() method but I'm concerned that is not sufficient.
Is this a reason for concern or is there perhaps some other option I am overlooking?
 
Joseph Kampf
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After re-reading your post, you have another issue.

Your opening the file each time. I suggest that you open your outputstream once and keep it open. You can do this in your Servlet.init() method and close the outputstream in your Servlet.destroy() method.

But your first statement is correct, you should be using a logging framework that does all of this heavy lifting for you.

Joe


Originally posted by Joseph Kampf:
You are using FileOutputStream directly?

I suggest that you try passing your FileOutputStream into the constructor of a BufferedOutputStream, then write to the BufferedOutputStream.

Joe



 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!