Created
November 1, 2013 06:44
-
-
Save ilkinulas/7261695 to your computer and use it in GitHub Desktop.
Thread.run() vs Thread.start()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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