File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes DB Interface question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "DB Interface question" Watch "DB Interface question" New topic
Author

DB Interface question

Chih-Wei Lee
Ranch Hand

Joined: Feb 20, 2008
Posts: 129
My DB interface has something like

public long lock(int recNo) throws RecordNotFoundException;

If my Data.java implement above method like this

public synchronized long lock(int recNo) throws RecordNotFoundException {
.
//code
}

I add a synchronized keyword.
This is the only one lock method in my Data.java
Does this method is still valid and implements interface?

Thanks

Lee


SCEA, SCJD, SCDJWS, SCWCD, SCJP
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Originally posted by Chih-Wei Lee:
My DB interface has something like

public long lock(int recNo) throws RecordNotFoundException;

If my Data.java implement above method like this

public synchronized long lock(int recNo) throws RecordNotFoundException {
.
//code
}

I add a synchronized keyword.
This is the only one lock method in my Data.java
Does this method is still valid and implements interface?

Thanks

Lee


I believe it could be ok, however, you might lose points on that. One of the goal in your locking mechanism (I think) is to synchronize as few lines as possible.

In your lock(), you might actually need to synchronize 2-3 lines while 3-4 other lines can afford to be run concurrently.

That's my opinion, I don't think you should do so, unless the interface forces you to.

Alex
Chih-Wei Lee
Ranch Hand

Joined: Feb 20, 2008
Posts: 129
Thanks for your response.
So can I have the same capability with below code

public long lock(int recNo) throws RecordNotFoundException {
synchronized(this){
.
.

}
}

I don't quite understand the keyword "this". Does it mean the class itself or the method itself.

Thanks
Quintin Stephenson
Ranch Hand

Joined: Nov 16, 2006
Posts: 40
Hi All

I've just signed up for my SCJD assignment today, so I don't know what the limitations are yet as I'm waiting for the emails to come through, so please excuse my ingorance.

Instead of using synchronize, why not use the lock interface. According to sun it provides a "more extensive locking operations than can be obtained using synchronized methods and statements. They allow more flexible structuring"

Cheers
Q


If at first you don't succeed, try, try again. If you don't try you have failed.
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Originally posted by Chih-Wei Lee:
Thanks for your response.
So can I have the same capability with below code

public long lock(int recNo) throws RecordNotFoundException {
synchronized(this){
.
.

}
}

I don't quite understand the keyword "this". Does it mean the class itself or the method itself.

Thanks


synchronizing on this means the class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DB Interface question
 
Similar Threads
About:My URLyBird1.3.2 Locking
NX:About DBMain interface
add new method in Interface DB
aonther problem surprised to me
Locking for URLyBird 1.1.1