Garbage Collection and Threads

Discussion in 'Java' started by Shirish Rai, Jun 9, 2004.

  1. Shirish Rai

    Shirish Rai Guest

    I have a class, say A which is runnable. When A is created it creates one
    or more threads. Thus each of these threads have a reference to the
    instance of A. Therefore when the client that created A is done using it,
    the instance of A cannot be garbage collected.

    Is there any way to notify the threads to exit when the thread that
    created A is done using it.

    Thanks.

    Shirish.
     
    Shirish Rai, Jun 9, 2004
    #1
    1. Advertising

  2. Shirish Rai

    Skippy Guest


    > I have a class, say A which is runnable. When A is created it creates one
    > or more threads. Thus each of these threads have a reference to the
    > instance of A.


    Only if you keep a reference floating around. If not, there is no reference
    kept anywhere and they will be garbage-collected some time later.
     
    Skippy, Jun 9, 2004
    #2
    1. Advertising

  3. Shirish Rai

    Chris Smith Guest

    Shirish Rai wrote:
    > I have a class, say A which is runnable. When A is created it creates one
    > or more threads. Thus each of these threads have a reference to the
    > instance of A. Therefore when the client that created A is done using it,
    > the instance of A cannot be garbage collected.
    >
    > Is there any way to notify the threads to exit when the thread that
    > created A is done using it.


    You'll have to take some explicit action at the end of the client that
    creates A. That action could involve setting a boolean flag inside A or
    interrupting the threads that are running A's code.

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Jun 9, 2004
    #3
  4. Shirish Rai

    Chris Smith Guest

    Skippy wrote:
    > > I have a class, say A which is runnable. When A is created it creates one
    > > or more threads. Thus each of these threads have a reference to the
    > > instance of A.

    >
    > Only if you keep a reference floating around. If not, there is no reference
    > kept anywhere and they will be garbage-collected some time later.


    It seems clear that in Shirish's case, the threads are created to run
    the instance of A in the first place, so yes they would reference it.

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Jun 9, 2004
    #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. Kevin Jackson
    Replies:
    1
    Views:
    429
    Alvin Bruney [MVP]
    May 28, 2004
  2. Andrew Mallinson

    Threads and Garbage Collection

    Andrew Mallinson, Jan 30, 2004, in forum: Java
    Replies:
    2
    Views:
    368
    Andrew Mallinson
    Jan 30, 2004
  3. Replies:
    8
    Views:
    9,727
    DrChaos
    Nov 17, 2005
  4. Øyvind Isaksen
    Replies:
    1
    Views:
    1,037
    Øyvind Isaksen
    May 18, 2007
  5. Brian Candler

    Threads preventing garbage collection?

    Brian Candler, Sep 17, 2008, in forum: Ruby
    Replies:
    11
    Views:
    222
    ara.t.howard
    Sep 18, 2008
Loading...

Share This Page