How does creating threads based on the number CPU cores per JVM differ with thread running on multiple JVMs creating the number of threads on the number of CPU cores, with the condition that all the JVMs runs on one physical system sharing the same CPU? In other words, a multi threaded Java program running 8 threads in parallel vs the same multi-threaded program running on 8 different JVMs sharing the same CPU?
I have given below some ways I found possibly to implement the parallel processing with threads, but could not understand the essential differences between them?
Approach one: A Thread queries the database changes periodically, starts (long running) threads in parallel (whenever changes occur) that works on the change data. (The work involves arithmetical and persisting the result to a database)
Approach two: Multiple threads queries the data changes in the database, locks the modified data, each thread starting a thread (from a thread pool) that process the change data.
Approach three: Multiple Threads, essentially run from different JVMs as separate processes, queries the database, locks the changed records it has found and starts thread (from the thread pool that each on of them have, max thread on the pool being of number of CPU cores) to process the change data.
Do the third approach is in anyway better than the other two? If yes/no why? (Because, as the monitoring threads runs on different JVMs, everyone of them can create as much threads as the CPU cores? As an example, in 8 core CPU, create 8 monitoring threads on separate JVM (as separate processes), with every one of them submitting the change jobs to a thread pool of 8? But, does not this argument fail, as there are only 8 physical cores and the processor can only run 8 threads at anytime?)
You have any other effective way to implement this scenario?