running standalone and caching issue

Charles Dupin

Ranch Hand

Posts: 94

posted 13 years ago

Hi, I have implemented some caching on the server to make sure that the data in the database is not re-read from the disk storage if no modifications was made to this data. This poses a problem when I run two times the application in standalone mode (no RMI): it starts two local servers, one server does not know the caching status of the other one. Of course this is not a natural situation as there is no controller running the two servers. What should I do: document the situation, remove the cache...?

Charles.<br />(SCJD2)

Peter den Haan

author
Ranch Hand

Posts: 3252

posted 13 years ago

Two Data instances running against a single file in separate JVMs will not work correctly anyhow, whether you have caching or not. Race condition galore. So don't worry. Nevertheless, consider removing the cache. It goes straight against the requirement not to complicate the design for performance's sake. - Peter

I would remove the cache as there is no requirement for it. Also the spec states that when in local mode the client and database run in the same vm, which means you will have no way of keeping two instances in sync.

Charles Dupin

Ranch Hand

Posts: 94

posted 13 years ago

Servers in Local mode? Maybe you are referring to something else

Of course I am referring to the DataModelServer that is directly connected to the client by a method factory in local mode. In remote client/server mode this method factory connects the client to a DataModelClient. Both data models are extending a DataModelAdapter. By the way when I remove my cache the answers to the client are a lot slower. Charles.

Charles, that kind of confuses me. Maybe I am getting caught up in the class naming that makes me misunderstand. You see in my design I have two classes DataAccessLocal and DataAccessRemote, both of these classes will be wrapped into a DataAccessFacade. This is the only class that the client gets in Local or in Remote mode, so the client never really knows what mode it is in. This might match what you have, but I am thrown off by the "DataModelServer" class name. I apologize if I am misinterpretting things. Mark

You are right Mark, my naming for these method is not very good. I will review it. By the way my method factory is returning depending on the local or remote connection: The server itself always connects to the DataModelServer. DataModelServer is in the server.jar DataModelClient is in the client.jar To be able to run the client in local mode I put the path of server.jar in the manifest of the client.jar . Charles.

Charles.<br />(SCJD2)

Chandra Peri

Ranch Hand

Posts: 46

posted 13 years ago

To Avoid starting two instances on same db file, I used filelock from FileChannel "java.nio" api package. Ofcourse you need jdk 1.4!