• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Andrew book persistDvd method ERROR?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Karol,

Hmm... I see your point.
[ July 16, 2008: Message edited by: Shengshuo Wu ]
 
Ranch Hand
Posts: 759
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for help and link to Errata.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic