• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Max, please comment your book.

 
Vlad Rabkin
Ranch Hand
Posts: 555
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Max,
I have two questions to the DVD project from your book. There are two things there which, to my opinion, are not
needed. Could you please confirm that they are really not necessary.
Otherwise I am not sure I understand the whole concept of multi-threading.
1. Vector.


Your reservedDVDs is a Vector. You synchronize explicetely on reservedDVDs.
Why do you use Vector instead of ArrayList?
Is it just because Vector is easer for "junior programmer" to understand?
What your idea about "nested locks"?


2. Locking on read.


You reserve(lock) DVD here. Why is you method in DVDDatabase class synchronized ?



Tx,
Vlad
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vlad,
I used Vectors so I can speak directly to your point, per page 115 and the FAQs. If I hadn't done it, I couldn't bring it up.
As for your later point, please see here. However, in this case, it's not necessary(as you correctly surmised). This was one of the points where my coauthors and I disagreed. That is, we all agreed that a dirty read was ok, but I was overruled on which way to present the example in the book. In retrospect, it was the right decision, I think. Without explanation, it's best to be safe: and I couldn't assume that everyone reading my book would post to me on this forum
M
 
Vlad Rabkin
Ranch Hand
Posts: 555
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Max,
Thanx you for yours answer. I must own up I am not sure I understood you, because of my bad English.
I used Vectors so I can speak directly to your point, per page 115 and the FAQs. If I hadn't done it, I couldn't bring it up.

Page 115 says there are two types of synchronization: object and client.
Vector is an example of object synchronization and synchronizatiting the whole block /method accessing Vector is a client synchronization.
Ok, but using "client synchronization" in your particular case is enought, since only we the object (vector) is accessed from the synchronized methods.
I am not sure I really understand in English "If I hadn't done it, I couldn't bring it up." Does it mean Vector is not needed(ArrayList would be enought), but Max used Vector just to explain what is object synchronization?

As for your later point, please see here. However, in this case, it's not necessary(as you correctly surmised).

I have carefully read the topic. Synchronization and synchronization of static methods is discussed there. I couldn't find an explanation there, since no static methods have been used in DVDDatabase, but "as you correctly surmised" probably say that it is not needed in this particular case.
Max or anobody else, could you help me and confirm if I understand Max correctly or not?
Tx,
Vlad
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vlad Rabkin:
Hi Max,
I am not sure I really understand in English "If I hadn't done it, I couldn't bring it up." Does it mean Vector is not needed(ArrayList would be enought), but Max used Vector just to explain what is object synchronization?

Yes, hence my assertion on page 115 that
it does not mean that you are using Vector in a Threadsafe way. If you wanted that guarantee, you would have to synchronize on the Vector object directly, just as you would have to synchronize directly on an ArrayList

I have carefully read the topic. Synchronization and synchronization of static methods is discussed there. I couldn't find an explanation there, since no static methods have been used in DVDDatabase, but "as you correctly surmised" probably say that it is not needed in this particular case.
Max or anobody else, could you help me and confirm if I understand Max correctly or not?
Tx,
Vlad[/QB]

I meant the first part of the discussion, where the 'Rancher asked me why the methods were synchronized. Yodon't need to do so in order to achieve a read, assuming that a dirty read is ok in your design.
All best,
M
 
Vlad Rabkin
Ranch Hand
Posts: 555
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Max,
Yodon't need to do so in order to achieve a read, assuming that a dirty read is ok in your design.

I do synchronize all methods (including find) on collection and therefore don't need to synchronize on Data.this (singletone) not to allow dirty reads and therefore I don't need a Vector. I hope it will be acceptable.
Tx MANY times. Your point is clear now to me. Sorry for asking you all these question. I just wanted to make sure I have made mistakes in my design.
Thank you!
Vlad
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem Vlad, it's always good to interact with you, Phil, Tony, Bharat, and the rest of the posters here. I hope you guys stick around and help out newer posters after you pass you exam
M
 
Vlad Rabkin
Ranch Hand
Posts: 555
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Max,
I hope you guys stick around and help out newer posters after you pass you exam

If I pass it... Otherwise I don't think my opinion will be valuable
Best,
Vlad
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I disagree. passing, at this point, would only validate to the rest of the world an option that I've already cultivated about you. You're a good developer, a careful engineer, and friendly guy
M
 
Vlad Rabkin
Ranch Hand
Posts: 555
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Max,

Well, honestly saying it is really big pleasure to hear such words from you.
I hope Sun will agree with you...
Whatever happens, it is great pleasure to talk to you and even greater pleasure to argue with you. I learned very much hear, (independantly from official results which can be bad or good).
I will do my best to stay always on-line, since it is the best place in Java word to learn something and share own knowledge with others.
Moreover it makes just fun to communicate with such people like Andrew, you, Phil, Bharat and others.
Best,
Vlad
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic