Thread_Runnable1
Thread OR Runnable:
  • A class implements Runnable, it shares the same object to multiple threads.
    • In Runnable one instance of a class is being created and it has been shared by different threads. So the value of counter is incremented for each and every thread access.
    • implements to many 
    • implements to signatures of interfaces or abstract classes
  • A Class extends Thread class (Superclass) , each of your thread creates unique object and associate with it.
    • extends once a super class and no more
    • extends for code reuses
  • Thread class internally implements the Runnable interface
  • Lambda way
    new Thread(
    () -> System.out.println("Hello -> from "
    + Thread.currentThread())
    ).start();

package javatemplate1;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

public class JavaTemplate1 implements Runnable{


@Override
public void run() {
//
for (int x = 1; x <= 3; x++) {
System.out.println(x + " Thread "
+ Thread.currentThread());}
//Lammbda way
for (int x = 1; x <= 3; x++) {
new Thread(
() -> System.out.println("Hello -> from "
+ Thread.currentThread())
).start();

}
//
} // end of void run
public static void main(String[] args) {
// TODO code application logic here
System.out.println("main block executing ");
JavaTemplate1 run1 = new JavaTemplate1();
Thread t1 = new Thread(run1);
t1.start();
//


//
}

}