package com.feigdev.androidserialsql;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by ejohn on 9/2/13.
 */
public class AccessDB {
    private static final LinkedBlockingQueue<Runnable> writerQueue = new LinkedBlockingQueue<Runnable>();
    private final GenericDBHelper dbHelper;
    private final SQLiteDatabase dbWrite, dbRead;
    ExecutorService executorService = new ThreadPoolExecutor(1, 1, 30, TimeUnit.SECONDS, writerQueue, new ThreadPoolExecutor.CallerRunsPolicy());

    public AccessDB(Context context, DefineDB myDB) {
        dbHelper = new GenericDBHelper(context, myDB);
        dbWrite = dbHelper.getWritableDatabase();
        dbRead = dbHelper.getReadableDatabase();
    }

    public SQLiteDatabase getReadableDB() {
        return dbRead;
    }

    private SQLiteDatabase getWritableDB() {
        return dbWrite;
    }

    public abstract class WriterTask implements Runnable {
        SQLiteDatabase db;

        public WriterTask() {
            this.db = getWritableDB();
        }

    }


}

@@ -988,24 +988,117 @@
 ead;%0A    %7D%0A%0A
+    public void addWriteTask(WriterTask task)%7B%0A        executorService.execute(task);%0A    %7D%0A%0A
     private 

Update AccessDB.java