• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to lock or unlock another Processes

 
yi lu
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are two Processes, not two Threads
we run "java test.class" twice and in two computers, how to wait or notify another Process in another computer?
[ January 02, 2004: Message edited by: yi lu ]
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not quite sure what your actual question is here and how it relates to the SCJD assignment.
But it sounds like you have two computes each with their won JVM running. So unless you have a server, where two server objects reside and both are trying to get a lock on an object on the Server, then you won't be abot to have then notify. Now you can have a Socket connection between the two computers, if they are on a network or Web access, but there is no need for this kind of interaction in the SCJD assignment, so a discussion on that should go into the Network forum.
Hope that helps.
Mark
 
yi lu
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in the instruction:
Record locking must be implemented using the methods public void lock(int) and public void unlock(int). These methods are required to allow concurrent use of the database when booking flights from multiple clients.
multiple clients must be in different computers and run the same jave class file, need the db-file change its format(add a lock mark field) to adapt the lock and unlock methods?
[ January 02, 2004: Message edited by: yi lu ]
 
Dennis Pettersson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When running two clients you connect to a server. The object on the server side should take care of locking, and is the same for both clients.
When running stand alone, without a server, you are not running two different JVM, sharing a single database file.
 
yi lu
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When running two clients you connect to a server. The object on the server side should take care of locking, and is the same for both clients.
-------------------------------------
I know I should take care of locking
and what I want to know is how to lock?
need the db-file change its format(add a lock mark field)? eg. when the lock mark field=0,the record is locked, when the lock mark field=1,the record is unlocked,
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Yi,


I know I should take care of locking
and what I want to know is how to lock?


The locking can be done in either way:
For thin client, locking is handled by the server, which access the DB.
For thick client, I am not sure how to do this, but from some of the threads here, some people implement their systems such that the client itself calls the lock function to lock the record.


need the db-file change its format(add a lock mark field)?


You cannot change the DB file format. You need to think of how the server knows the record is being locked. Some people use DataManager to handle it, while some use java.util.Collection objects to handle it.
You may also refer to Max's book, he has introduced a good idea on how locking is performed in his book. I use his approach as well.
I guess you may search for this, but I strongly recommend you think of it before reading others ideas.
Hope this help.
Nick.
 
yi lu
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, I know I can lock it by a static variable
but, if I do not lock the WHOLE database(the file) when any client modify only ONE record,
then when two client modify two different records at the same time(it is OK for not locking mark in two different records),
it means two program write ONE file at the same time,
Can the system(like windows) support two program write ONE file at the same time?
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Yi,


Can the system(like windows) support two program write ONE file at the same time?


This depends on how you *define* the term "program". If it means Client, then, no matter how many clients you have, since we have 1 single server only (or more acturate, one instance access the database file), it wont cause any problems.
But if it means Server, I think the database file is likely to be corrupted since there is no way for 2 JVM to know whether the other is writing it EVEN you have a DB lock.
In this case, maybe you need some additional trick. For example, when one thread is writing to the DB file, before it writes, it creates (say) a dummy file db.lock. If it already exists, it waits until it is not exists, and the re-create it (to indicate the file is accessing), after update the file, the current thread remove this file (to indicate the file is finished access).
In my implementation, I simply assume there is one server runs on a machine, operating with the DB file. I have documented that, if more than 1 server running in the same machine that accessing the same DB file, the DB file maybe corrupted, and I have not provided any recovery mechanism for it.
Nick.
 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Yi,
It seems that you are trying to do something you should not be doing. What you should be trying to do is have only one running application physically accessing the database. In standalone mode this will be your client application. In multi user mode this will be the server application:

In your instructions you should have the statement "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.".
In other words Sun are guaranteeing to you that they will never run two standalone clients simultaneously. Nor will they run the standalone client and the server simultaneously. Nor will they run two servers simultaneously.
In the multi user situation, if your client tries to lock a record, it must send that lock request to the server and wait for a response. The server will do the actual locking. So if two clients try and lock the same record, the server will grant the lock to one client, and then wait until that first client releases the lock. It will then grant the lock to the second client.
Note that the clients themselves are not doing any locking, and so they do not need to communicate between themselves. All they are doing is calling a method on the server.
Regards, Andrew
 
yi lu
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot, something still unclear to me:
-------------------------
in the instruction:
Architecturally, the application is a traditional client-server system. There are three key parts: the server-side database with network server functionality, the client-side graphical user interface, and a client-side database client part that handles the networking on behalf of the user interface.
Additionally, the program must be able to work in a non-networked mode. In this mode, the database and user interface run in the same VM and no networking is performed, and no sockets should be created. The user must be able to select the operating mode, although it is acceptable that the program stay in one mode once it has started up.
--------------------------
db-file in A computer
a client in A computer
b client in B computer
Client a <------(non-networked mode)------->Database in A computer
Client b <----->Server in A computer<------>Database in A computer
when "a" client use non-networked mode and "b" client use network mode, in this situation, how does the Server handle(lock/unlock) the request from "a" client
 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Yi,

Originally posted by Yi Lu:
db-file in A computer
a client in A computer
b client in B computer
Client a <------(non-networked mode)------->Database in A computer
Client b <----->Server in A computer<------>Database in A computer
when "a" client use non-networked mode and "b" client use network mode, in this situation, how does the Server handle(lock/unlock) the request from "a" client


It doesnt.
Sun have guaranteed that they will not run the non networked client at the same time as the server. That was what I was saying with:

Originally posted by Andrew Monkhouse:
In your instructions you should have the statement "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.".
In other words Sun are guaranteeing to you that they will never run two standalone clients simultaneously. Nor will they run the standalone client and the server simultaneously. Nor will they run two servers simultaneously.


When the server is running, it can be certain that there are no other applications running that might access the database. So it only needs to worry about locking for the clients that are connected to the server.
Regards, Andrew
 
yi lu
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry, these sentences do not exist in my instruction. 55555555555~~~~
--------------------------------------------------------------------------------
Originally posted by Andrew Monkhouse:
In your instructions you should have the statement "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.".
In other words Sun are guaranteeing to you that they will never run two standalone clients simultaneously. Nor will they run the standalone client and the server simultaneously. Nor will they run two servers simultaneously.
--------------------------------------------------------------------------------
if non networked mode can't run along with network mode, does it means in non networked mode, I need not consider lock/unlock because of only one client?
[ January 05, 2004: Message edited by: yi lu ]
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Yi,
I think it is reasonable that, only network mode, or non-network mode should be run in a machine at one time for accessing the database server.
Although my instruction also do not contain the statement that Andrew's provided, I have simply added this as one of my assumptions in my choice.txt. In addition, it is better for us to document any reasonable assumptions or how we handle those unclear instructions too.


if non networked mode can't run along with network mode, does it means in non networked mode, I need not consider lock/unlock because of only one client?


You may say so, however, it may result in implementing the server with 2 cases. But in general, I think the locking part can be used even for standalone mode, as it has no harm, and it wont affect the performance much because only 1 client. You may rethink about this part.
In my implementation, I have used the same server with locking for both modes.
Nick.
 
What? What, what, what? What what tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic