This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes static RandomAccessFile variable or non-static one Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "static RandomAccessFile variable or non-static one" Watch "static RandomAccessFile variable or non-static one" New topic
Author

static RandomAccessFile variable or non-static one

Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341
Hello everyone.
I see most people in this forum using a static RandomAccessFile variable on both singleton and non-singleton Data class, but I don't understand that why they have the static RAF instead of a local RAF variable? Please anyone tell me.
Thank you,
Surasak Lee
Jacques Bosch
Ranch Hand

Joined: Dec 18, 2003
Posts: 319
Hey there.
I also used a singleton Data object approach, but I used a local private member raf. I also don't see the benefit of having the raf static. It makes no difference in mi opinion. Perhaps I am wrong... Somebody tell us.
J


Jacques<br />*******<br />MCP, SCJP, SCJD, SCWCD
Steven Hoodless
Ranch Hand

Joined: Mar 23, 2004
Posts: 64
It depends on your file-access mechanism. For example, you may have multiple Data classes all sharing access to one static RandomAccessFile.
By locking on the static RAF you can prevent multiple synchronous access from corrupting the file.
Steven


SCJP, SCJD, SCWCD.
Jacques Bosch
Ranch Hand

Joined: Dec 18, 2003
Posts: 319
That makes sense. But what I'm talking about is a static raf versus a non-static raf within a Data singleton. No benefit as far as I can see.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static RandomAccessFile variable or non-static one
 
Similar Threads
NX: Physical locking
Nested synchronized for raf
B&S no lock cookies
NX: UrlyBird data file format question
Do we need synchroniation with Singleton Data class