This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
So when query from the data file, the whole file is locked, and no other operation can be taken on it until the lock released. That's not performant at all. Beside, if my query fetches millions of records from data file, then the whole world is waiting for me . It seems pagination should be used here.
Am I right?
SCJP 6 with 93%
Oracle Database SQL Expert with 98%
Don't know about yours, but my assignment says something along the lines: no other application will use the same file, so you only need to synchronize it on a single application level (either synchronzied blocks or java.util.concurrent locks). If you use FileLock, you prevent other applications from accessing it, which is always nice, but not required by the specs.
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.
"At most one program is accessing the database file" means I can only lock the object that access the database file. Because if I use FileLock to lock a portion of data file, another thread can still lock another portion if they are not overlapped.
And the following from official documentation also discourages me from using FileLock.
File locks are held on behalf of the entire Java virtual machine. They are not suitable for controlling access to a file by multiple threads within the same virtual machine.