Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Crazy synchronization question

 
Ranch Hand
Posts: 55
  • 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 ]
 
Ranch Hand
Posts: 399
  • 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
  • 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
  • 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
 
Tick check! Okay, I guess that was just an itch. Oh wait! Just a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic