android - Thread vs Handler for polling -


i need polling thread perform network operations every 5 mins. came following 2 solution. better , why? looking have minimum cpu , battery usage.

pollthread = new thread(){       public void run(){           while(toggle) {               // stuff               sleep(five_minutes);           }       } }; pollthread.start(); 

or

runnable dostuffrunnable = new runnable() {      @override      public void run() {          // stuff          handler.postdelayed(this, five_minutes);      } } 

the answer depends on whether using handler handle other tasks well. if not, there won't difference; there still thread wakes every 5 minutes want. if handler handles other tasks, using handler more efficient having separate thread each task, requires 1 thread, , may have optimizations respect processor usage.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -