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
Marshal
Joined: Mar 22, 2005
Posts: 35224
7
posted
0
new Thread().start()
You're not creating an instance of the Tintin class, but an instance of the Thread class.
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
Joined: Jul 15, 2009
Posts: 536
posted
0
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.
[ SCJP 6.0 - 90% ] , JSP, Servlets and Learning EJB.
Try out the programs using a TextEditor. Textpad - Java 6 api
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.