SCJA, SCJP (1.4), SCJD
SCJP, SCJD, SCWCD, OCPJBCD
SCJP, SCJD, SCWCD, OCPJBCD
_ _ ________________________ _ _ <br /> <br />Just SCJP (but 93%)
Originally posted by William Smith II:
I'm at a standstill in my assignment. I'm questioning the thread safety of RandomAccessFile as well. I've written a little multi-threaded tester for my Data class. When I use one thread, my Data class works perfectly. But when I have 2+ threads going, the output on the file is unpredictable and incorrect. The file ends up being corrupt because a record is written it a byte or two off, it writes out null values where a record should be, but other records look OK. It's very sporadic. So it's got to be a thread safety issue.
My Data tester uses one and only one Data object. The Data object creates the RandomAccessFile object in the constructor so there can only be one. My data tester basically implements runnable and takes Data as a parameter. I use a lock manager which I use on an update or create which is basically a Set. The lock manager is created as part of the Data object so again one and only one lock manager is created.
I've synchronized on RandomAccessFile and a host of other objects in the hopes of solving the problem but to no avail. It seems to me the file pointer may be getting changed between thread accesses despite RandomAccessFile being locked by a synchronized(raFile) { .. }
Anyone else having problems with RandomAccessFile and thread safety?
SCJP, SCWCD, SCBCD, SCJD, BB Java2 and JSP1.1
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
|