Search code examples
androidmultithreadingconcurrencyexecutors

Android java.util.concurrent.Executors newSingleThreadScheduledExecutor example


I am having a problem with Android java.util.concurrent.Executors.

I am trying to use newSingleThreadScheduledExecutor to run my runnable every x seconds. I saw executor.scheduleAtFixedRate(myTask, 0, 50, TimeUnit.MILLISECONDS); however it doesn't exists in Android.

The Android documentation link , does not give a clue how I should use the newSingleThreadScheduledExecutor;

Could someone give me an example how I should use it to run a runnable every x seconds? I know you can use Handler, but I am wondering how you can use SingleThreadScheduledExecutor to do the same.

Thanks in advance.


Solution

  • You can get an example here: http://www.java2s.com/Code/JavaAPI/java.util.concurrent/ExecutorsnewSingleThreadScheduledExecutor.htm

    Actually Executors comes with Java 7 .