Added retry loop to threaded db ops.
While in right place
Merge pull request #388 from arjclark/db-locking-improve

db locking mitigation