Red-Folder / Cordova-Plugin-BackgroundService

BackroundService plugin for use with Cordova (PhoneGap)
144 stars 85 forks source link

LogCat messages: "Plugin should use CordovaInterface.getThreadPool()" #19

Closed frell closed 9 years ago

frell commented 11 years ago

Hello,

Thanks for a great plugin.

I've noticed lots of these sorts of messages in my Logcat. All works fine, but think it could be causing some UI lag. Any suggestions?

THREAD WARNING: exec() call to BackgroundServicePlugin.getStatus blocked the main thread for 25ms. Plugin should use CordovaInterface.getThreadPool().

Phonegap v3.0 Android : 4.3

Red-Folder commented 11 years ago

I have seen this warning message before ... however I don't believe I can do any further work to improve it.

The code is already using getThreadPool and follows the pattern as described here (see the getThreadPool example) -> http://docs.phonegap.com/en/2.7.0/guide_plugin-development_android_index.md.html#Developing%20a%20Plugin%20on%20Android

If you look at the code within the source repository (https://github.com/Red-Folder/Cordova-Plugin-BackgroundService-Source/tree/master/src/com/red_folder/phonegap/plugin/backgroundservice). The difference is that the logic split into a separate class to allow it to be decorated with the appropriate interface.

I've possibly got something wrong in the threading logic - but I'm afraid I can't spot it. I'm open to suggestions.

Red-Folder commented 11 years ago

Having done some further research I wonder if it is related to the variables (used in the run) not being final.

See this article -> http://stackoverflow.com/questions/11424753/why-do-variables-passed-to-runnable-need-to-be-final

Red-Folder commented 11 years ago

I've tried some changes - but that's completely broken it ;)

I'll review the changes over the next couple of days .... but this "final" may well be a red herring.

frell commented 11 years ago

Your efforts are very much appreciated.

Interesting, although a little over my head. The phonegap example does seem to point towards your point about final as the line before the getThreadPool() call is;

final long duration = args.getLong(0);

Im polling the getStatus regularly (5 second interval) from the UI. Maybe i need to reduce this to help work around the problem. Is there a better way to for the UI to be notified of new data from the service? I.e. having the service invoke somesort of callback to the UI when it has something to say, rather than the UI keeping polling a question.

Red-Folder commented 11 years ago

I have another issue raised (https://github.com/Red-Folder/Cordova-Plugin-BackgroundService/issues/17) which asks for the Plugin to push the latest results to the HTML/ JavaScript. When this is done, you should be able to remove the getStatus every 5 seconds.

I hope to get to that issue in the next couple of weeks.

Red-Folder commented 10 years ago

Just to update;

I've release the code for issue https://github.com/Red-Folder/Cordova-Plugin-BackgroundService/issues/17 - this means that you can register for updates rather than use setInterval. May help.

I will look at this issue again (the warning) - maybe in a week or two. I'd like to look at the repo/ Plugman work (https://github.com/Red-Folder/Cordova-Plugin-BackgroundService/issues/20) first.

frell commented 10 years ago

Awesome. I'll test that out when i can get back onto that project

Red-Folder commented 9 years ago

Issue moved to https://github.com/Red-Folder/bgs-core/issues/26