This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads

 
Gurpreet Saini
Ranch Hand
Posts: 295
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello

I am using the following code but it compiles fine but do not print "In Run" in console . Whats the reason behind this ?. Please help . Thanks in advance .

public class Tintin implements Runnable{
public static void main(String ...args) {
new Thread().start();
}

public Tintin() {
}

public void run() {
System.out.println("In Run");
}

}
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
new Thread().start()

You're not creating an instance of the Tintin class, but an instance of the Thread class.
 
Gurpreet Saini
Ranch Hand
Posts: 295
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks friend
 
Mo Jay
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to specify the object instance that you to run the thread on, do the following and it should work fine:



Cheers!!!
 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Job that is done is the thread class's run() which has nothing and neither has been overriden. To make your run execute you need to tell the thread to use your run() by passing the job instance.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic