aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S: Same Questions 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 "B&S: Same Questions" Watch "B&S: Same Questions" New topic
Author

B&S: Same Questions

Laura Pecoraro
Ranch Hand

Joined: Mar 31, 2009
Posts: 45
Hi all agains

I have same question, because my solution don't satisfy me fully

Lock
I implements a simple locks (using the Lock interface & List of records locked)... so

For my opinion the read function CAN reads a record lock, but, possible incoherence of data occurs...
Same ideas

RMI
I implements a RMI connection (an direct connection), manages by a Connector class (returns DBMain reference by specified connection type)...
I must implements the DBMain (by Sun) & implements DBMainRmi (by me) for manage the RMI service

But, this way, I must "RE"mapping the DBMain interface into DBMainRmi because the RecordNotFoundException not match with RemoteException... I would like NOT "re"mapping the DBMain

It is possible??

Thanks...

Laura



K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 1973
    
    7

Hello Laura, you seem to make some progress

About the locking - What do you think? Will the read thread able to get the "latest" or "updated" value? IMO as long as some thread "updates" the data, any threads that read AFTER the update will get the upated value. It's all in the timing.

About the RMI, you do need to figure out the architecture - meaning what methods are exposed to the clients. Have a look at these thread A and thread B. When deciding what methods to expose really includes if the client can access the lock and unlock methods of the Data class.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7
Laura Pecoraro
Ranch Hand

Joined: Mar 31, 2009
Posts: 45
K. Tsang wrote:Hello Laura, you seem to make some progress

About the locking - What do you think? Will the read thread able to get the "latest" or "updated" value? IMO as long as some thread "updates" the data, any threads that read AFTER the update will get the upated value. It's all in the timing.

About the RMI, you do need to figure out the architecture - meaning what methods are exposed to the clients. Have a look at these thread A and thread B. When deciding what methods to expose really includes if the client can access the lock and unlock methods of the Data class.


Thanks for your supports

About the locking the Sun specifications say


If I to understand, no CPU cycles, NO WAIT UNLOCK RECORD... Its true

Or I notify all to waits this unlocked record

I make some progress... My solution is 80% completed... so and so...
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 1973
    
    7

OK think about this. Where do you wait? If a record is already locked, do you need to wait in order to unlock it? Same goes for update/delete methods. How do you ensure only one record is locked? How to make it thread-safe?
Laura Pecoraro
Ranch Hand

Joined: Mar 31, 2009
Posts: 45
K. Tsang wrote:OK think about this. Where do you wait? If a record is already locked, do you need to wait in order to unlock it? Same goes for update/delete methods. How do you ensure only one record is locked? How to make it thread-safe?


Ok... a solution is notifyAll when a record is unlocked, but, in this case an operation must be waits... I don't like...

I thinks notify immediately if a record is Locked (for delete/update) operation using the Exception (RecordNotFoundException)... for reads, notify when an record is unlocked...

Do you think about this

Laura

K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 1973
    
    7

Laura Pecoraro wrote:Ok... a solution is notifyAll when a record is unlocked, but, in this case an operation must be waits... I don't like...

I thinks notify immediately if a record is Locked (for delete/update) operation using the Exception (RecordNotFoundException)... for reads, notify when an record is unlocked...


First you need to decide these things:
* How many threads can read at the same time?
* How many threads can write at the same time?
* Do read operations (eg read, find, getXXX) need to wait/notify?

Most threads do reads more often than writes. In my approach, I only allow 1 thread to write. Since locking is required for writes (lock -> update/delete -> unlock) I wait until the record is locked.

For the notify in the unlock method, can you control which thread to notify? No so notifyAll is the appropriate way to go - not necessarily the best approach.

Just a reminder, for the create menthod, locking should be done internally.

Oh don't think about performance or speed like you are tending to do. The goal is to get the app works and do the correct functionalities correctly. The Data class/server/locking together is worth 160 points. And without locking you can't pass (80 points).
Julio Cesar Marques
Ranch Hand

Joined: Mar 21, 2009
Posts: 66
Hi Laura! It seems your problem is about Lock, my question is about C/S communication algorithm. Locking is a thing that you have to write only by Server side. My problem is how the best way to do a C/S comm and not lose points on this item.


Julio Cesar Lopes Marques
Sun Certified Java Developer 5, Sun Certified Java Programmer 5
Julio Cesar Marques
Ranch Hand

Joined: Mar 21, 2009
Posts: 66
Ops!! My bad! I had seen another post and just mixing everything...
;)
Laura Pecoraro
Ranch Hand

Joined: Mar 31, 2009
Posts: 45
Thanks All
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: B&S: Same Questions
 
Similar Threads
NX:About DBMain interface
DBMain method need throw RemoteException?
UrlyBird RMI Interface
Can my Data class implement an interface which extends the DataAccess interface?
[UB1.3.3] DBMain Question! Help me plz..