dontkillmy-app icon indicating copy to clipboard operation
dontkillmy-app copied to clipboard

The custom thread executor is posting runnable on main thread

Open mohit92 opened this issue 2 years ago • 2 comments

The test is supposed to schedule repetitive tasks on the main thread, a custom thread executor. However, if you check the code it seems to be executing the runnable on the main thread for both the cases

executor?.scheduleAtFixedRate(Runnable {
            h.post(Runnable {
                Log.i(TAG, "Work") // Here you can see Looper.myLooper() == Looper.getMainLooper() returns true
                currentBenchmark.workEvents.add(System.currentTimeMillis())
                checkBenchmarkEnd(currentBenchmark)
            })
        }, WORK_REPEAT_MS, WORK_REPEAT_MS, TimeUnit.MILLISECONDS)

you can see Looper.myLooper() == Looper.getMainLooper() returns true in the runnable, Is this expected?

mohit92 avatar May 06 '22 09:05 mohit92

Hello @mohit92 this is true, but in general we do not expect the main thread to be restricted but other threads not. So the aim here is to see whether the system restricts other thread more then the main thread. But you are right that it would be nicer to completely separate this from the main thread.. Many thanks for pointing this out

petrnalevka avatar May 06 '22 11:05 petrnalevka

Thanks for the confirmation. I think moving the Runnable out of h.post should do the job.

mohit92 avatar May 06 '22 11:05 mohit92