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 ]