1

I have a small example that i run on a real device with 4+4 cores.

ExecutorService service  = Executors.newFixedThreadPool(4);

for(int i =0 ; i<1000; i++){

Runnable task = new Runnable() {
        @Override
        public void run() {
            //Insert customers in Room
            app.repocustomers().insertcustomers(em); 10k customers
        }
    };

service.execute(task);
}

When i run it with only one Executors.newFixedThreadPool(1), the execution time is smaller than with 4 and i cant understand why.

Because of the multicores, each thread is on a different core and ready when the database unlocks. Does waiting causes the overall execution to be slower than one thread? There is no overhead on switching threads because they are on different cores.

Note I measure the times with System.millisecs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.