Vi Matviichuk
Vi Matviichuk

Reputation: 1132

using cordova getThreadPool.execute() over AsyncTask in Android plugin

What is the preferred approach in cordova plugin to handle multithreading? async execution can be performed this way:

cordova.getThreadPool().execute(new Runnable() {
  public void run() {
  // actions
  }
}

or using default AsyncTask implementation.

Which one is preferred in which cases?

Upvotes: 2

Views: 2513

Answers (1)

Vi Matviichuk
Vi Matviichuk

Reputation: 1132

Cordova recommends using cordova.getThreadPool().execute() execution. This is so because thread pool is handled by cordova framework. Otherwise, async tasks thread pool will be handled by android OS.

It does not really matter for small applications, when there is not so much interoperability between js and java-plugins. But for complex apps this can become a potential issue, especially in case when you have several async tasks being running at once.

It is preferred to use separate thread pool for communication between js and java-plugins layer (cordove.getThreadPool()) and another separate thread pool for android background processing (asynctasks)

Upvotes: 2

Related Questions