javascript - Java how to detect variable change -
i have cordova plugin , working. however, while loop wait until hashmap has seems inefficient. there better way?
public class myapp extends cordovaplugin { static hashmap<string,string> myprop = new hashmap<string,string>(); protected void plugininitialize() { } public boolean execute(string action, jsonarray args, callbackcontext callbackcontext) throws jsonexception { if (action.equals("init")) { appconnectionservice.requestconfig(cordova.getactivity()); init(callbackcontext); pluginresult.status status = pluginresult.status.no_result; pluginresult pluginresult = new pluginresult(status); pluginresult.setkeepcallback(true); callbackcontext.sendpluginresult(pluginresult); return true; } return false; } private void init(final callbackcontext callbackcontext) { while(myprop.isempty()) { } pluginresult result = new pluginresult(pluginresult.status.ok, myprop.get("myid")); result.setkeepcallback(false); callbackcontext.sendpluginresult(result); } public static boolean handleconfig (bundle config) { if (config != null) { // add entries came in config display adapter (string key: config.keyset()) { myprop.put(key, config.getstring(key)); } } else { log.d("myapp", "failed"); } return false; } }
so on javascript part call init()
, , return "myid", way waiting result busy loop:
while(myprop.isempty()) { }
is there more efficient , robust way wait result?
that looks place use wait
, notify
.
https://docs.oracle.com/javase/tutorial/essential/concurrency/guardmeth.html
Comments
Post a Comment