  Because 
        <code class="function">countRecords()</code> 
        reads every record in the database, if used incorrectly the thread
        will self-deadlock.  The writer thread has just written 500 records
        to the database, but because the transaction used for that write
        has not yet been committed, each of those 500 records are still
        locked by the thread's transaction. If we then simply run a
        non-transactional cursor over the database from within the same
        thr