Thursday 25 August 2011

Java DateFormat and thread safety

Reminder: DateFormat is not thread safe.   It's a very easy trap to fall into.

See Javadocs:
Date formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.
And multiple other blogs:


Tuesday 23 August 2011

Anemic Domain Models and Spring

I guess it started with J2EE and entity beans - people started creating lots of lovely domain classes and obediently created getter and setter functions for the data (good OO practice as we all know).  But they totally forgot about bunching object behaviour together in the same class.  Instead we often see "Service Layers" above the Domain Layer which implement all logic.


It's suprising how many text books and tutorials are out there advocating this approach.  In addition, DI containers such as Spring give you a strong nudge in that direction.  For example, you'll more than likely want to perform CRUD operations on your objects.  For this you'll require some kind of session/entity manager and you'd like this to be injected into your object by the container.  And for this to happen the object needs to be managed by your container.  Ah, problem - typically domain objects are application managed.  So people end up with Singleton Service or DAO objects which are managed by the container, injected with the session/entity manager and do all the CRUD operations, etc on their respective domain objects.  It can be argued that is not proper OO.  It should be noted however that people's opinons do differ:


There is a solution.  It's used in the Spring Roo generated classes and is explained in the link below.  Be warned, it involves Load Time Weaving:

Monday 15 August 2011

Windows 2003: system user home directory

From Microsoft: "The system account and the administrator account (Administrators group) have the same file privileges, but they have different functions. The system account is used by the operating system and by services that run under Windows."

My service needed a configuration file to be placed in the home directory.  Where is the system (ie root) user home directory?  C:\Windows\system32\config\systemprofile  Obvious, right?  ;)

Tuesday 2 August 2011

Returning to your previous location in the Eclipse editor

You search, say, on the location of a variable/method declaration and then you'd like to return to your previous location.

Alt + LEFT ARROW

You can navigate through your positional history using Alt + LEFT ARROW and Alt + RIGHT ARROW.  (NB same shortcut is used to go back or forward a page in most web browsers)

Eclipse Shortcuts