Devrath
Devrath

Reputation: 42824

Difference between handler and Scheduler

I am trying to Understand the difference between Handler & Scheduler


What I know::


IN - JAVA(Not Android)

  1. Java uses JVM
  2. In Java Scheduler takes care of switching the control back and forth between main-thread and the worker-threads
  3. It quickly happens and so its called multi-threading.
  4. The developer has no access to scheduler and only he can influence the scheduler, JVM takes care of scheduler functionality

IN - ANDROID

  1. Android uses JVM
  2. A scheduler is called a Handler in android
  3. Advantage is that developer has access to Handler through which he can control the scheduling of threads

My Questions::

  1. Are my explanations correct ?
  2. Are both handler and scheduler functionality wise the same ?
  3. If my explanations are not correct what are the difference between Handler and scheduler ?
  4. Advantages of using handler in android w.r.t Scheduler in Java ?

Thanks !

Upvotes: 2

Views: 1163

Answers (1)

Budius
Budius

Reputation: 39836

I don't believe your expansions are correct and the two are pretty different. Android is a Java machine and still have a scheduler not accessible to the developer.

Handler holds the "handle" of one specific thread. To the Looper of the thread to be more specific (so only threads that "loops" may have handlers).

The handler allows the developer to request some code to be processed in a specific thread either as soon as possible (using the post method) or after some time (using the postDelayed method).

Note that the methods are called 'post'. That means the code will be posted to the scheduler and the scheduler will actually run the code on the requested thread whenever it is time for that thread to be execute.

PS. I answer that from my mobile, sorry for any misspellings.

Upvotes: 2

Related Questions