jQuery in Action, 2nd edition*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Crazy synchronization question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Crazy synchronization question" Watch "Crazy synchronization question" New topic
Author

Crazy synchronization question

Krishna Varma Adluru
Ranch Hand

Joined: Nov 24, 2001
Posts: 55
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

Joined: Feb 22, 2001
Posts: 399
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

Joined: Nov 24, 2001
Posts: 55
John,
You understood right ..!!! Thank You ...!!!
Now, I got it ...
Regards,
Krishna Varma Adluru
Krishna Varma Adluru
Ranch Hand

Joined: Nov 24, 2001
Posts: 55
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Crazy synchronization question
 
Similar Threads
Does this mean automatic failure ?
Design Opinion
Remote Interface
NX: (Contractors) Interfaces and design question
Writing Data Client