Hi David,
First of all: posting complete code snippets of your solution is not allowed (because they could just be copied by someone else) (I deleted them from your post)
Secondly I understand your solution (without and your Data class is indeed thread-safe (can easily be tested with Roberto Perillo's Data class
test, an excellent test case and 1 of the most valuable threads in this forum).
What I was trying to explain: your Data class is thread-safe <==> all threads work on the same instance. So your snippet will work without any problem, because you have just 1 instance per database file. But if another developer would create a business service and expose this service using the factory
pattern through RMI (like described in the
SCJD book by Andrew Monkhouse):
this solution will not be thread-safe anymore, because you will have multiple Data instances: each of them will be thread-safe but not together. And of course an easy fix would be just to mark
data static. So you need to document how the Data class is supposed to be used. If your Data class is a singleton, it can't be used wrongly.
But like I already said your approach is completely fine (and will work without any problem)! This is just what this certification is about: making decisions and argumenting why you chose one above another.
With my final remark I just meant:
Kind regards,
Roel