THREADING IN JAVA

A Simple Java Program On Thread_

 

package threading.in.java;
class Threaddemo extends Thread{
public void run()
{
for(int i=1;i<5;i++){

try{Thread.sleep(1000);}catch(InterruptedException e){System.out.println(e);}
System.out.println(i);
}
}
public static void main(String args[]){
Threaddemo t1=new Threaddemo();
Threaddemo t2=new Threaddemo();
try
{
t1.start();
t2.start();
t1.join();
t2.join();

}
catch(Exception ex)
{
System.out.println(ex);
}
System.out.println(“completed”);
}
}

 

Output Of The Following Program_

1
1
2
2
3
3
4
4

completed

1 thought on “THREADING IN JAVA”

  1. Nice program to understand java thread .
    Please write a program of Java Thread to executed select statement in JDBC and show their results.

Leave a Reply