public void flush() {
        while (true) { 
          cs:synchronized(this) { 
                disableRehash = true;
                long n;
                do {
                    n = nModified;                    
                    for (int i = 0; i < table.length; i++) { 
                        Entry e, next, prev;
                        for (e = table[i], prev = null; e != null; e = next) { 
                            Object obj = e.ref.get();
                            next = e.next;
                            if (obj != null) { 
                                if (db.isModified(obj)) { 
                                    db.store(obj);
                                }
                                prev = e;
                            } else if (e.dirty != 0) { 
                                break cs;
                            } else { 
                                count -= 1;
                                e.clear();
                                if (prev == null) { 
                                    table[i] = next;
                                } else { 
                                    prev.next = next;
                                }                            
                            }
                        }
                    }
                } while (n != nModified);
                disableRehash = false;
                if (count >= threshold) {
                    // Rehash the table if the threshold is exceeded
                    rehash();
                }
                return;
            }
            runtime.runFinalization();
        }
    }