dontkillmy-app
dontkillmy-app copied to clipboard
The custom thread executor is posting runnable on main thread
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?
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
Thanks for the confirmation. I think moving the Runnable out of h.post should do the job.