The Artima Developer Community
Sponsored Link

Legacy Design Forum
Finalization and Cleanup

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Approach 2 exclusive resource

Posted by RAY YE on September 29, 2000 at 3:51 PM

Hi, Bill

In your article "Object finalization and cleanup", the approach 2 (LogFileManager), you wrote
"This design also allows a client to monopolize the resource for as long as it wants. A client can write several consecutive messages to the log file without fear that another thread or process will slip in any intervening messages. Once a client successfully opens a log file with openLogFile(), that log file belongs exclusively to that client until the client invokes closeLogFile()."

Considering in a multithreaded enviroment, and you pass the reference of LogFileManager to different thread(client), each thread(client) would be able to share the resource to write messages to the same log file. In order to provide integrity, I think at least the method "writeToFile" should be "synchronized". Is this correct?

Thanks,




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us