Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The custom thread executor is posting runnable on main thread #24

Open
mohit92 opened this issue May 6, 2022 · 2 comments
Open

The custom thread executor is posting runnable on main thread #24

mohit92 opened this issue May 6, 2022 · 2 comments

Comments

@mohit92
Copy link

mohit92 commented May 6, 2022

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 mohit92 changed the title The custom thread executor is posting runnable on main thread as well The custom thread executor is posting runnable on main thread May 6, 2022
@petrnalevka
Copy link
Contributor

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

@mohit92
Copy link
Author

mohit92 commented May 6, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants