amit sharma777

Greenhorn
+ Follow
since May 25, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by amit sharma777

perhaps the following looks better,also do we really need to use a Boolean lock variable and obtain a lock to this variable I don't think if there is a case of corruption in this case because once it's false no other thread can access it.

private boolean lock=true;
public void lock(int record)throws IOException{
synchronized(v){
while((v.contains(new Integer(record)))| |(v.contains(new Integer(-1)))| |(lock==false)){
try{
v.wait();
}
catch(InterruptedException e){
throw new IOException("lock failed");
}
}
while(lock){
while((v.size()>0)&(record==-1)){
lock=false;
try{
v.wait();
}
catch(Exception b){}
}
v.add(new Integer(record));
break;
}
}
}
anyways I was looking for somr other approach in this case i.e without a boolean flag or something else
and in the implementation you can delegate calls to the DataServer
Taking your second approach for a moment why 2 classes if you can make your Data class implement the DataServer interface then only the exceptions never have to catch them specifically for local & remote
I think I did not make myself clear Now is the DataServerImpl a wrapper class that wraps a data class object or is it something else In my last post I made the assuption that it was a wrapper.In that case the question of a stub does not arise on the local mode.I think it is not a very good idea to have two classes when one can do------polymorphism??
well i guess your DataServer is a wrapper around the Data class object and i think that you are implementing two different interfaces for server & client(why?).Implement the same interface for both and if your DataServer is a wrapper then why not to implement the same interface for Data class.In this way in the client wrapper you could do something like this:
DataInterface d;
public ClientWrapper(---reemote--){
d=Naming.loo____
}
public ClientWrapper(----local---){
d=new Data(---)
}
Hi Rick, the idea there is that once a client calls a full db lock no other thread can lock after that & it should also wait for the records already inside the lock to finish
I wanted to know if there can be another approach to implementing a database lock and some suggestions on my approach
private boolean lock=true;
public void lock(int record)throws IOException{
synchronized(v){
while((v.contains(new Integer(record)))| |(v.contains(new Integer(-1)))){
try{
v.wait();
}
catch(InterruptedException e){
throw new IOException("lock failed");
}
}
while(lock){
while((v.size()>0)&(record==-1)){
lock=false;
try{
v.wait();
}
catch(Exception b){}
}
v.add(new Integer(record));
break;
}
}
}
why to have two different classes for remote & local mode.I think one class should handle this .
Hi Conor,
Do you mean that the client should perhaps implement the same interface that the Data class on the Server is implementing in this way we can just have a reference to that interface no matter if it is remote or local.Can you give me any other purpose of implementing the methods of the Data class on the Client apart from the fact that they can be used in the local mode.
I have not tried to use wait or notify in my lock method but instead i've synchronized on the record I've locked.It seems to work fine please see code:
The variable v here is the vector containing the records.
public void lock(int record) {
try{
DataInfo uu=getRecord(record);
if((v.size()!=0)){
for(int i=0;i<v.size();i++){>
if ((v.size()==0)| |(!(((DataInfo)v.elementAt(i)).getValues()[0]).equals(getRecord(record).getValues()[0]))){
synchronized(uu){
v.addElement(uu);
}}
}
}
else{
synchronized(uu){
v.addElement(uu);
System.out.println(v.contains(uu));
}
}
}
catch(DatabaseException q){
System.out.println(q.getMessage());
}
}
please give me some suggestions on this code .
I am not clear as to why should the client class implement all the public methods of the Data class .If we write an RMI server which implements all the public methods and export it to the client as well as adding the client to a vector in the server by putting a client stub in the server classpath ---it appears to work.