• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Space pants. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic