I am trying to run multiple threads in parallel. I tried to achieve this with multiple instances of the stream. My assumption is that it will be executed at the same time; however, threads execute in sequence.
Here is the simple code I tested:
new Thread(new Runnable() {
@Override
public void run() {
for (int i=0; i<100; i++) {
LMLog.info("THREAD", "Counting " + i + " in Thread A");
}
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
for (int i=0; i<100; i++) {
LMLog.info("THREAD", "Counting " + i + " in Thread B");
}
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
for (int i=0; i<100; i++) {
LMLog.info("THREAD", "Counting " + i + " in Thread C");
}
}
}).start();
And the log shows that the for loop executes one after another
Counting from 0 to 99 in a thread A, followed by the same in Thread Band Thread C.
Based on this, I came to the conclusion that they are not executed in parallel, as I thought, they will be, but rather in sequence.
How can parallel execution be done on Android?