Some time back, I had to write a program where I need to have a thread which continuously looks for some status and does some work in background.
So, I started off like this.
Class MyThread implements Runnable
{
public void run()
{
//Something here
}
}
Class MyClass
{
public void function1()
{
MyThread thread = new MyThread();
thread.run(); // assuming thread runs in background
//do my work here
}
}
And I was wondering, why my program is taking so much time. And then, I figured out, that thread is running and my program is exiting only after thread finishes its work. :)
Later, my teammate asked me "Did you find out where you are wrong? " and explained where I was wrong. :)
Some times, we do such silly mistakes for which we waste hours and hours. :)
Tuesday, December 19, 2006
Funny code
Subscribe to:
Post Comments (Atom)
2 comments:
Hmm.. where is the error?
I should call start() method rather run() method. For that I have to encapsulate my MyThread object in Thread object.
Post a Comment