File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URLyBird 1.3.3 Locking question

 
Ching-Tien Chang
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 327
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 327
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mr.Anthony:
Thanks for your kindly answer,
I will pay more attention on my locking mechanism.

Sincerely
Ching-Tien Chang
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic