Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Crazy synchronization question

 
Krishna Varma Adluru
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a quick question regarding synchronization();
Let's go through an example:
I have an interface called DataAccess like:
interface DataAccess {
.
.
public void lock() throws Exception;
.
.
}
Another interface called RemoteDataAccess like:
interface RemoteDataAccess extends DataAccess {
.
.
public void lock() throws RemoteException;
.
.
}
Class RemoteDataAdapter like:
public class RemoteDataAdapter implements RemoteDataAccess {
.
.
public synchronized void lock() {
}
.
.
}

Client will only have access only to DataAccess interface depending on local or Remote.
My question is whether we will loose the synchronized behaviourof Lock method in RemoteDataAdapter as we cannot declare lock() method as synchronized in DataAccess interface ?

Am I going crazy ?

Thanks,
Regards,
Krishna Varma Adluru
[ April 11, 2002: Message edited by: Krishna Varma Adluru ]
[ April 11, 2002: Message edited by: Krishna Varma Adluru ]
 
John Dale
Ranch Hand
Posts: 399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I understand your question, but see if this helps you answer it.
As I understand it,
synchronized void lock() { blah }
is equivalent to
void lock() { synchronized(this) { blah } }
The calling code does not pay any attention to the modifier "synchronized", which is why it is not part of the method signature, and not used in the interfaces.
 
Krishna Varma Adluru
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John,
You understood right ..!!! Thank You ...!!!
Now, I got it ...
Regards,
Krishna Varma Adluru
 
Krishna Varma Adluru
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,
Another quick question.
We all have a Data class like:
public class Data {
.
.
public synchronized DataInfo getRecord(int recNum) throws DatabaseException {
}
.
.
}
I have a RemoteDataAdapter class which adapts to
Remote Connections like:
public class RemoteDataAdapter {
Data data = null;
public RemoteDataAdapter(Data data) {
this.data = data;
}
.
.
public DataInfo getRecord(int recNum)
throws RemoteConnection, DatabaseException {
data.getRecord(recNum);
}
.
.
}

Should I declare getRecord() method in
RemoteDataAdapter also to be synchronized ? What are the pros and cons of it ? Are there any performance issues ?
Please note that there is only 1 line of code in the getRecord() method of RemoteDataAdapter class.
Thanks,
Regards,
Krishna Varma Adluru
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic