Originally posted by Daniel Haupt:
Hi folks,
I've implemented my Data-Class and the locking mechanism as well so far, the JUnit-Tests posted some where in this forum perform fine as well.
I've still got a question according the RandomAccessFile class. Is it threadsafe?
Currently the RandomAccessFile is a instance member of my Data class?
Do I have to synchronize access to the seek, read and write-methods?
Or do you advise to create a new instance of the RandomAccessFile reading my database file in each method of my Data class (create, update, delete)?
Thanks
Daniel
Cheers, Roberto Perillo
SCJP, SCWCD, SCJD, SCBCD
Originally posted by Roberto Perillo:
And also, my Data class is a singleton, and all its methods are synchronized, so we can guarantee that no more than 1 thread is reading/writing to the file at a time.
did your instructions come with synchronized methods ? You are currently not providing concurrent read as (most probably) requires your assignment..
Also, all your methods being synchronized, wouldn't it be pretty much the same as synchronizing on a single member variable RAF..
Please tell me if I'm way off..
Cheers, Roberto Perillo
SCJP, SCWCD, SCJD, SCBCD
Your server must be capable of handling multiple concurrent requests, and as part of this capability, must provide locking functionality as specified in the interface provided above. You may assume that at any moment, at most one program is accessing the database file; therefore your locking system only needs to be concerned with multiple concurrent clients of your server. Any attempt to lock a resource that is already locked should cause the current thread to give up the CPU, consuming no CPU cycles until the desired resource becomes available."
Locks a record so that it can only be updated or deleted by this client.
If the specified record is already locked, the current thread gives up
the CPU and consumes no CPU cycles until the record is unlocked.
Consider Paul's rocket mass heater. |