Thread safe database handler