Explicitely calling Thread.run

Discussion in 'Java' started by Phaedrus, Jul 5, 2003.

  1. Phaedrus

    Phaedrus Guest

    Hi Gang
    I just wanted to know that in what cases will it be advisable to call
    the Thread's run method ourselves?
    TIA
    -Manu Anand
    Bangalore,India
    Phaedrus, Jul 5, 2003
    #1
    1. Advertising

  2. In article <>,
    says...
    > Hi Gang
    > I just wanted to know that in what cases will it be advisable to call
    > the Thread's run method ourselves?


    Is short: none.

    Calling run() directly causes method to be run on current Thread. Calling
    ..start() causes new Thread to be initialized, and automatically calling run()
    after initialization.

    In you need to call run() directly, create new method. You can call that
    method from run() anyway, if needed.


    Regards,
    Harri Tuuloskoski
    Harri Tuuloskoski, Jul 5, 2003
    #2
    1. Advertising

  3. On Sat, 05 Jul 2003 11:01:14 -0700, Phaedrus wrote:

    > Hi Gang
    > I just wanted to know that in what cases will it be advisable to call
    > the Thread's run method ourselves?
    > TIA
    > -Manu Anand
    > Bangalore,India


    This is a BAD idea. The problem is that if you create a Thread but never
    call its start() method, then it will never die and never be eligible for
    garbage collection. If you keep doing this your program will inevitably
    run out of memory.

    I suggest that you create Runnable objects instead of extending Thread.
    Then you have a choice of either calling "myRunnable.run();" to do the
    work yourself, or of doing "new Thread(myRunnable).start();" if you want
    another thread to do the work.

    Extending Thread causes other confusions as well, so it really is best to
    avoid doing this.

    Steve
    Steve Horsley, Jul 6, 2003
    #3
  4. Phaedrus

    Roedy Green Guest

    On 5 Jul 2003 11:01:14 -0700, (Phaedrus) wrote
    or quoted :

    >I just wanted to know that in what cases will it be advisable to call
    >the Thread's run method ourselves?


    see http://mindprod.com/jgloss/thread.html

    If you do, it runs just like an ordinary method without starting a new
    thread.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, Jul 6, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Amelyan
    Replies:
    0
    Views:
    384
    Amelyan
    May 24, 2005
  2. Victor Bazarov

    Calling constructor explicitely

    Victor Bazarov, Feb 23, 2005, in forum: C++
    Replies:
    9
    Views:
    4,468
    Ron Natalie
    Feb 24, 2005
  3. mathieu
    Replies:
    4
    Views:
    397
    Kai-Uwe Bux
    Aug 12, 2006
  4. jacob navia
    Replies:
    3
    Views:
    552
    Nick Keighley
    Feb 24, 2010
  5. Keith Thompson
    Replies:
    10
    Views:
    685
    Tim Rentsch
    Mar 3, 2010
Loading...

Share This Page