Skip to content

Instantly share code, notes, and snippets.

@ilkinulas
Created November 1, 2013 06:44
Show Gist options
  • Save ilkinulas/7261695 to your computer and use it in GitHub Desktop.
Save ilkinulas/7261695 to your computer and use it in GitHub Desktop.
Thread.run() vs Thread.start()
Runnable runnable = new Runnable() {
public void run() {
// do something...
}
};
Thread thread = new Thread(runnable);
// 1. Thread run metodunu cagirirsan runnable current thread (thread.run()'i cagiran) icinde calisir.
// Bazen Unit test yazarken run metodunu cagiriyoruz. bu sayede Runnable icindeki islemler senkron yapilmis oluyor.
// run() metodundan cikildiginda run metodu icindeki islemlerin yapildigindan eminiz.
thread.run();
// 2. Thread start() metodu runnable içindeki run metodunun yeni olusturulan thread tarafindan calistirilmasini saglar.
// start() metodundan cikildiginda yeni olusturdugumuz thread henuz runnable'in run metodunu calistirmamis olabilir. (Asenkron)
thread.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment