thread safety for db