This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why Denny's DVDs DvdFileAccess.database is not static?

 
Mika Tapanainen
Ranch Hand
Posts: 95
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

Andrew Monkhouse's and Terry Camerlengo's Denny's DVDs is an excellent example application!

But I don't understand why DvdFileAccess.database is not static?

If I start the server and then two clients the application creates two DvdFileAccess.database instances. How can the application now get the unique access to the database (for example in
the method DvdFileAccess.retrieveDvd)?

Thanks,

Mika
 
Roel De Nijs
Sheriff
Posts: 9186
77
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mika,

I'm not Andrew, but I'll give it a shot. Take a look at the following line in DvdDatabase:


So it doesn't matter how many DvdDatabase instances are created (one for each client), there will be just 1 shared instance of the DvdFileAccess class (and so there is no need to have DvdFileAccess.database marked static).

If you check ReservationsManager you'll see this comment:
We rely on the class which uses this ReservationManager to ensure that only one instance exists for any reservations.

The same applies for the DvdFileAccess class.

Hope it helps!
Kind regards,
Roel

 
Nicolas Kal
Ranch Hand
Posts: 69
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mika,

Although I havn't seen Andrew Monkhouse's and Terry Camerlengo's Denny's DVDs application, I suppose that the DvdFileAccess class is on the server side since you mentioned that you are working with a server. Furthermore I suppose that this is some kind of interface implementation providing communication between client and server. If this is the case then you don't have any problem. In simplified words, when the server starts it makes its instances, clients requesting an instance of the DvdFileAccess class will all get the same instance rather than creating new DvdFileAccess for every request.

Regards,
Nicolas
 
Mika Tapanainen
Ranch Hand
Posts: 95
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roel,

your answer helped me.

BR,

Mika
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic