Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative way to threads under Android

Android's Java and Oracle's Java are slightly different. Is it possible to use the following actors or coroutines

  • http://code.google.com/p/jetlang/
  • http://incubator.apache.org/s4/
  • http://www.malhar.net/sriram/kilim/
  • http://code.google.com/p/coroutines/

also for Android in order to avoid to use threads and share more code between Android's Java and Oracle's Java? Are there other frameworks available for both Java versions.

Thank you in advance.

like image 330
user977828 Avatar asked Jul 13 '12 13:07

user977828


People also ask

Is threads available on Android?

Threading in AndroidIn Android, you can categorize all threading components into two basic categories: Threads that are attached to an activity/fragment: These threads are tied to the lifecycle of the activity/fragment and are terminated as soon as the activity/fragment is destroyed.

Is multithreading possible in Android?

Developers multithread Android applications in order to improve their performance and usability. By spinning off processor- or resource-intensive tasks into their own threads, the rest of the program can continue to operate while these processor intensive tasks finish working.

How many types of threads are there in Android?

Android has four basic types of threads. You'll see other documentation talk about even more, but we're going to focus on Thread , Handler , AsyncTask , and something called HandlerThread .

Are coroutines better than threads?

So, it's not a “magical” technology, that is better than threads, but just a different concept of concurrency used in your applications. Unlike threads, coroutines are not bound to any particular thread. A coroutine can start executing in one thread, suspend execution, and resume on a different thread.


1 Answers

You should try actors from Java version of Akka: http://doc.akka.io/docs/akka/snapshot/java/untyped-actors.html

It allows easy growing of actor topology using best practices (no direct access to actors by Java reference, limiting failures to zones, limiting overload using scheduler zones etc.) - all of them are described in free copy of "Scala in Depth" book: http://typesafe.com/resources/scala-in-depth

Here is example (with demo http://vimeo.com/20303656) of dynamic behavior of actors using Akka FSM on Android: https://github.com/akka/akka/blob/master/akka-samples/akka-sample-fsm/src/main/scala/DiningHakkersOnBecome.scala

Also you can try lightweight actors from Functional Java: https://github.com/functionaljava/functionaljava/blob/master/core/src/main/java/fj/control/parallel/Actor.java

Most minimalistic version of an actor for JVM is here: https://github.com/plokhotnyuk/actors/blob/master/src/test/scala/com/github/gist/viktorklang/Actor.scala (its features described here: How to implement actor model without Akka? )

like image 96
Andriy Plokhotnyuk Avatar answered Oct 13 '22 23:10

Andriy Plokhotnyuk