Multi Threading Programming
Multi Threading Programming
Multi-Threading Programming
Session 11 & 12
Outline
- Introduction
- Thread Concept
- Creating Tasks and Threads
Inside run( ), we will define the code that constitutes the new thread.
Creating Tasks and Threads
public class MyClass implements Runnable {
public void run(){
System.out.println("MyClass running");
}
}
To execute the run() method by a thread, pass an instance of
MyClass to a Thread in its constructor (A constructor in Java is a
block of code similar to a method that's called when an instance of
an object is created).
When the thread is started it will call the run() method of the
MyClass instance instead of executing its own run() method. The
above example would print out the text "MyClass running ".
Creating Multiple Threads
The output:
References
• Daniel Liang, Y., 2015, Introduction to java programming, vol.10,
Pearson Education, New Jersey.
• Thread:
– https://dzone.com/articles/java-thread-tutorial-creating-
threads-and-multithr
Bina Nusantara 13