SQLite Forum

Multithread processing, storing in memory and writing to database
Login
Background:
I am working on creating a daemon process to collect metrics like CPU, memory, UFS usages and so on every x seconds. 
For each of the metric, I create one worker thread. It's job is to collect the data, process it, write to database in memory. (Each thread will have its own instance of database in memory) and wait for x seconds.
Each worker thread and a table in the database are tightly coupled.

Main thread responsibility is on a event, it will request all worker thread to write/flush data from memory to actual database in the filesystem.

Environment: Linux

Approach 1:
1. As explained above, each worker thread will have its own instance of database in memory.
2. Main thread will notify worker thread to flush data from memory to DB in filesystem

Approach 2:
1. Share one connection instance (memory) across all worker threads
2. Main thread will flush data from memory to DB since it has access to memory instance.

My questions:
1. Which approach should I take? 
2. Do I need to handle any concurrent accessing issues? Reason for asking this is each thread will update one specific table.
3. Or is there any other approach?

Thank you