• Post Reply Bookmark Topic Watch Topic
  • New Topic

[NX: URLyBIRD 1.1.2]. synchronization,constructor, static variables and unit test  RSS feed

Roel De Meester
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
My design
I have a singleton Data class implementing SUN's DB interface.
The only class fields are
private static Data;
public static Data getInstance(){..}
I have not started the remote part yet. I'm only unit testing and load testing (JunitPerf) the Data.class for the moment.
My Data constructor does not take arguments since i expect the db-location to be in the suncertify.properties (if not i take a default_value). This is documented in javadoc and choices.txt.

I have not synchronized any methods! I synchronize all DB-access by putting synchronized(raf){ .. } around each raf access.
I synchronize all locking(with cookie) by putting synchronized(lockedRecord){ .. } around all lock access.
My Questions
1. raf and lockedRecord and cookie are private instance variables. They are not static because i'm using a singleton already. Is this correct design?
2. If the Data has never been constructed, and two clients try to getInstance() at the same time. How does this behave? Will They both get into the constructor since for both of them instance == null? And if so .. how is this prevented?
3. Does anyone have experience (unit)testing the correct synchronization and locking of the Data class.
4. deadlocks. Is it true to say that putting a synchronized block within another synchronized block is bad practice? I have the impression i'm doing weird stuff in my delete method which automatically unlocks itself. Could anyone comment?
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!