explain this keyword in Thread

Page 1 of 1

0 Replies - 1332 Views - Last Post: 24 March 2013 - 05:05 AM Rate Topic: -----

#1 joshuajobin08   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 17-September 12

explain this keyword in Thread

Posted 24 March 2013 - 05:05 AM

why this is used in the below program. I am not able to understand the use of it.When i remove that this keyword my output is not displayed. While when i write ,it displays the output.
import java.io.*;
class printmsg{
synchronized void printmember(int n){
try{
System.out.println("start");
for(int j=n;j>0;j--){
if(j==n/2)
Thread.sleep(10);
System.out.println(j);
}
System.out.println("end");
}
catch(Exception e){

System.out.println(e);}
}
}
class demo implements Runnable{
int n;
printmsg pt=new printmsg();
Thread th=new Thread(this);
demo(printmsg p,int x){
pt=p;
n=x;

th.start();
}
public void run(){
pt.printmember(n);
}
}
class demo3{
public static void main(String args[]){
printmsg p=new printmsg();
demo d1=new demo(p,16);
demo d2=new demo(p,8);
demo d3=new demo(p,10);

}
}



i am having doubt in this part.
Thread th=new Thread(this);


Is This A Good Question/Topic? 0
  • +

Page 1 of 1