File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Why Denny's DVDs DvdFileAccess.database is not static? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Why Denny Watch "Why Denny New topic
Author

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

Mika Tapanainen
Ranch Hand

Joined: Jun 11, 2009
Posts: 95
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


SCJP, SCJD, SCEA
http://fi.linkedin.com/in/mikatapanainen
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5266
    
  13

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


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Nicolas Kal
Ranch Hand

Joined: Sep 09, 2009
Posts: 69
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


SCJP 6.0 , SBCD (Preparing..),
MSc Enterprise Systems Development, BSc Computer Science
Mika Tapanainen
Ranch Hand

Joined: Jun 11, 2009
Posts: 95
Hi Roel,

your answer helped me.

BR,

Mika
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why Denny's DVDs DvdFileAccess.database is not static?