aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes URLyBird 1.3.3 Locking question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "URLyBird 1.3.3 Locking question" Watch "URLyBird 1.3.3 Locking question" New topic
Author

URLyBird 1.3.3 Locking question

Ching-Tien Chang
Greenhorn

Joined: May 31, 2004
Posts: 16
Dear all:
here is my question...

public class Data exntends UnicastRemoteObject implements DBMain {
public synchronized String[] read(int recNo) throws
RecordNotFoundException, RemoteException {
//implement
}
public synchronized void update(int recNo, String[] data) throws
RecordNotFoundException, RemoteException {
//implement
}
public synchronized void delete(int recNo) throws
RecordNotFoundException, RemoteException {
//implement
}

// other method implementation ......
}

Every client will get the same Data object,
if ClientA wants to delete(13), there is no need to lock(13) first,
because ClientA must had object lock first and then can execute delete(13), in the situation, which client have data object lock, and the client is the only thread that allowd to access the database.
why still need lock(), unLock(), isLock() mechanism?

hopes my question is clearly ^^"
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
If every method in your Singleton style Data class is synchronized, then simultaneous reads and writes are not possible. Many programmers want to support at least simultaneous reads, so they don't synchronize every method of the Data class and make it a Singleton.

You are right though - if you implement the Data class this way, there is no need for locking/unlocking on a record level.
Ching-Tien Chang
Greenhorn

Joined: May 31, 2004
Posts: 16
Thanks you Mr.Anthony, this is the answer that want ^^

another question:
please reference the thread:
http://www.coderanch.com/t/183457/java-developer-SCJD/certification/NX-URLyBird-single-remote-object

the topics discuss about "single remote object or multi-remote object?"
thought many people reply for this topic, but still no answer about
"why not just use one single remote data class for each client and any disadvantage??"

could anybody give me answer? thanks vary much.
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
If you have a single Data instance that has a RandomAccessFile as a data member, then you would have to address the thread safety issues that occur when multiple threads are trying to move the RandomAccessFile's pointer around. With multiple Data instances, you do not have that problem.
Ching-Tien Chang
Greenhorn

Joined: May 31, 2004
Posts: 16
Mr.Anthony:
Thanks for your kindly answer,
I will pay more attention on my locking mechanism.

Sincerely
Ching-Tien Chang
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: URLyBird 1.3.3 Locking question
 
Similar Threads
B&S: Locking aproach
About:My URLyBird1.3.2 Locking
implementing interface methods within another interface method
locking and synchronization question
NX:About DBMain interface