File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes File-level locking? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "File-level locking?" Watch "File-level locking?" New topic

File-level locking?

Richard Hull

Joined: Jul 01, 2002
Posts: 2
Just wondering what the general consensus is regarding file-level locking in the assignment.
Without it, it is entirely possible to have a server running, with 2+ clients working happily with record-locking maintaining consistency in the servers JVM, but what happens, say, if I start up another client (in local-mode this time), and the file I pick happens to be the database file that the server is currently using.
If the record-locking is maintained in the servers JVM, then the additional local client won't know anything about the servers locks, and might well update the database, causing corruption in the file.
Charles Miller

Joined: Jun 28, 2002
Posts: 19
That's a valid point and, as you have probably figured out, the instructions don't cover that. For my submission, I made note of that in the user documentation... that if a connection to a particular database is in local mode, that no other connections should be made to that database (local or remote). Hopefully my solution is sufficient.
Eduard Jodas
Ranch Hand

Joined: May 14, 2002
Posts: 80
I'm not completely sure but I think you can't open a random access file twice for update.
Anyway, jdk1.4 allows you to lock a file.
Chiji Nwankwo
Ranch Hand

Joined: Jun 21, 2002
Posts: 56
I was under the impression that we needed 2 copies of the db.db file. One that resides on the client side and the other residing one the server side. This way there would be no conflict.
Please correct me if I am wrong in thinking that.

SCJP, SCJD, SCWCD<br />"Meekness is not weakness, but power under control"
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Local mode and server mode will be using different db.db files. Or should I jsut say that the assessor will not run both at the same time. Don't worry about this situation.

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: File-level locking?
It's not a secret anymore!