Exno 7
Exno 7
No:7
Implement an application that implements Multi threading
Aim:
Algorithm:
}
});
Thread thread3 = new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 5; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
handler.sendEmptyMessage(t3);
}
}
});
Handler handler = new Handler() {
public void handleMessage(android.os.Message msg) {
if(msg.what == t1) {
tvOutput.append("\nIn thread 1");
}
if(msg.what == t2) {
tvOutput.append("\nIn thread 2"); }
if(msg.what == t3) {
tvOutput.append("\nIn thread 3"); }
}};}
Output:.
Result:
Thus the program to implement the multithreading was executed
successfully.