-
Notifications
You must be signed in to change notification settings - Fork 6
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
Functions blocking main thread frequently #22
Comments
I have to admit to being very confused over the "Plugin should use CordovaInterface.getThreadPool()" message. The code is already using:
This seems to match the example shown in the docs -> http://docs.phonegap.com/en/2.3.0/guide_plugin-development_android_index.md.html I've seen the warning on my Background Service as well (open issue -> Red-Folder/Cordova-Plugin-BackgroundService#19) - but never understood why it is occurring. I'll have a fresh look. |
Further notes to myself; Taken from https://github.com/apache/cordova-android/blob/master/framework/src/org/apache/cordova/PluginManager.java:
Within CordovaActivity.java, the getThreadPool as :
"threadPool" is defined as java.util.concurrent.Executors.newCachedThreadPool() |
I believe I've made a fundamental mistake with how I'm using the Runnable class. While I'm defining the logic with new Runnable.run() (which in then passed to the getThreadPool().execute()), that code if making reference to lots of methods of the parent class (the plugin) - which I suspect is causing locking issues. I think I need to be creating a new class (SchedulerLogic) which extends Runnable and move the run and logic code into that class. Then on getThreadPool().execute() pass a new SchedulerLogic. I probably also need to put some syncronization round any dal amendment (addAlarm, updateAlarm & cancelAlarm) and release on save - may try to push this in to the DAL to ensure that its atomic. Likely to need to employ some level of dispose ... example code:
|
First job will be to create a repeatable test - probably a loop which creates 50 alarms should do it. |
[Another note to myself] Read http://tutorials.jenkov.com/java-concurrency/thread-signaling.html for ideas |
Take a look at Katzer's code for a local notification plugin. When I originally used the plugin it suffered from the same problem, then in an update he documented a fix and it seemed to solve the problem for the most part (instead of nearly a third of added notifications blocking the main thread, I might get 1 or 2 when adding 50-100 notifications). https://github.com/katzer/cordova-plugin-local-notifications |
From my logcat when trying to call any js scheduler function:
when trying to cancel alarms:
When trying to add alarms:
When trying to getAlarms():
I can't tell for certain, but it seems like when the main thread is blocked, that the corresponding function doesn't go through... I have a counter that increases everytime I make a call to my addAlarmAtTime(passedTime) function, and the number from the the counter is quite a bit higher than the length of alarms array that I get from getAlarms()...
For example, the counter is 56, when the length of the array that holds the alarms is only 37...
The text was updated successfully, but these errors were encountered: