wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Andrew book persistDvd method ERROR? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Andrew book persistDvd method ERROR?" Watch "Andrew book persistDvd method ERROR?" New topic
Author

Andrew book persistDvd method ERROR?

Karol Wiszowaty
Greenhorn

Joined: Jul 16, 2008
Posts: 3
Hi all!

There is some strange code in Andrew's book project soure code. I think the method DvdFileAccess.persistDvd() has error.
When you are adding new record the offset is calculating:
<blockquote>code:
<pre name="code" class="core">
offset = database.length();
</pre>
</blockquote>
But there is no lock on database on that time. Another thread can easily enter the method and get the same offset beacuse writing to database is made some lines farther:
<blockquote>code:
<pre name="code" class="core">
synchronized (database) {
database.seek(offset);
database.write(out.toString().getBytes());
}
</pre>
</blockquote>
So another thread can rewrite new record.

Am I right?
Thanks for help.
[ July 16, 2008: Message edited by: Karol Wiszowaty ]
Shengshuo Wu
Greenhorn

Joined: May 28, 2008
Posts: 6
Hi Karol,

Hmm... I see your point.
[ July 16, 2008: Message edited by: Shengshuo Wu ]

SCJP, SCWCD, SCJD
Jeffry Kristianto Yanuar
Ranch Hand

Joined: Oct 01, 2007
Posts: 759
Hi, check out for the book's errata in

http://apress.com/book/downloadfile/2611

Jeffry Kristianto Yanuar
SCJP 5.0
SCJA
SCJD (Working on UrlyBird 1.3.2 : almost done)
Karol Wiszowaty
Greenhorn

Joined: Jul 16, 2008
Posts: 3
Thanks for help and link to Errata.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Andrew book persistDvd method ERROR?