the way suncertify.db.Data is provided to us it opens file in "rw" mode so it automatically uses the db file exclusively, you don't need to worry about that.
However, if you leave it as is, an attempt by another thread to open the db will result in exception
Gennady:
Let me clarify what I said.
Let us assume there is one instance of Data associated with db.db. If you now create a second instance of Data (associated with db.db just like the first instance), we will then have two
instances both reading/writing db.db. This will create problems since there is no synchronization across them.
I do not think that an attempt to create a second instance will throw an exception as you appear to suggest. Correct me if I am wrong.
With a Singleton, you prevent the creation of a second instance of Data in the same JVM (but it will not prevent additional instantiations of Data from other JVMs).
Actually we WILL want to permit other instances of Data as long as each instance is reading/writing separate binary database files. Because each binary file is like a separate table in the
database. (There is only 1 table for this developer assignment.)
So what we really want to do is to ensure that at most one Data object is reading/writing db.db i.e. what we really want is a file lock.
[This message has been edited by Thomas Mathai (edited October 23, 2001).]
[This message has been edited by Thomas Mathai (edited October 23, 2001).]