Question on multi-thread execute the same method of same classinstance

Discussion in 'Java' started by QQ, Mar 28, 2008.

  1. QQ

    QQ Guest

    Hi all

    Just want to ask when multi-thread execute the exact the same method
    what happened?

    each thread create its own space to save method variables....??
    Thanks

    Steven
     
    QQ, Mar 28, 2008
    #1
    1. Advertising

  2. Hi,

    yes, for what regards variables defined in the method, they are
    created in a different copy for every executing thread. Of course this
    doesn't happen to variables defined outside the method, and this is
    the case where synchronization could be required.

    So long,
    Stefano

    On Mar 28, 11:47 am, QQ <> wrote:
    > Hi all
    >
    > Just want to ask when multi-thread execute the exact the same method
    > what happened?
    >
    > each thread create its own space to save method variables....??
    > Thanks
    >
    > Steven
     
    Stefano Brocchi, Mar 28, 2008
    #2
    1. Advertising

  3. Re: Question on multi-thread execute the same method of same class instance

    "Stefano Brocchi" <> wrote in
    message
    news:...
    > Hi,
    >
    > yes, for what regards variables defined in the method, they are
    > created in a different copy for every executing thread. Of course this
    > doesn't happen to variables defined outside the method, and this is
    > the case where synchronization could be required.


    This is true and in addition there is a separate copy of local variables
    each time the method is activated, including multiple instances within the
    same thread.

    Matthew Humphrey http://www.iviz.com/
     
    Matt Humphrey, Mar 28, 2008
    #3
  4. QQ

    Guest

    On Mar 28, 10:06 pm, Stefano Brocchi
    <> wrote:
    > Hi,
    >
    > yes, for what regards variables defined in the method, they are
    > created in a different copy for every executing thread. Of course this
    > doesn't happen to variables defined outside the method, and this is
    > the case where synchronization could be required.
    >
    > So long,
    > Stefano
    >
    > On Mar 28, 11:47 am, QQ <> wrote:
    >
    > > Hi all

    >
    > > Just want to ask when multi-thread execute the exact the same method
    > > what happened?

    >
    > > each thread create its own space to save method variables....??
    > > Thanks

    >
    > > Steven


    Thank you very much.
     
    , Mar 28, 2008
    #4
  5. QQ

    Guest

    On Mar 28, 10:30 pm, "Matt Humphrey" <> wrote:
    > "Stefano Brocchi" <> wrote in
    > messagenews:...
    >
    > > Hi,

    >
    > > yes, for what regards variables defined in the method, they are
    > > created in a different copy for every executing thread. Of course this
    > > doesn't happen to variables defined outside the method, and this is
    > > the case where synchronization could be required.

    >
    > This is true and in addition there is a separate copy of local variables
    > each time the method is activated, including multiple instances within the
    > same thread.
    >
    > Matthew Humphreyhttp://www.iviz.com/

    Thank you very much for that.
     
    , Mar 28, 2008
    #5
  6. QQ

    Lew Guest

    wrote:
    > Thank you very much.


    You actually don't need to permanently fill the newsgroup archives with
    numerous redundant and superfluous unnecessary repetitive frequent but polite
    "thank you" posts. Just let the information stand on its merit for all to see.

    --
    Lew
     
    Lew, Mar 28, 2008
    #6
  7. QQ

    Roedy Green Guest

    Re: Question on multi-thread execute the same method of same class instance

    On Fri, 28 Mar 2008 03:47:00 -0700 (PDT), QQ <>
    wrote, quoted or indirectly quoted someone who said :

    >Just want to ask when multi-thread execute the exact the same method
    >what happened?
    >
    >each thread create its own space to save method variables....??
    >Thanks


    Local variables live on a stack. Each thread gets its own stack. So
    each thread has its own copy of any local variables. However they
    share the instance and static variables. You have to use locking,
    volatile and other tricks to make sure the threads don't interfere
    with each other.

    See http://mindprod.com/jgloss/thread.html
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Mar 28, 2008
    #7
    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. roni
    Replies:
    2
    Views:
    413
    Wessel Troost
    Apr 12, 2005
  2. =?Utf-8?B?Y2hyaXN2Yw==?=

    thread.start() does not actually execute the assigned method

    =?Utf-8?B?Y2hyaXN2Yw==?=, Apr 27, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,256
    davidallen
    Jun 10, 2007
  3. zxo102
    Replies:
    5
    Views:
    389
    zxo102
    Aug 15, 2006
  4. liu yang
    Replies:
    4
    Views:
    2,016
    Antoninus Twink
    Jul 28, 2008
  5. Savas Ates
    Replies:
    1
    Views:
    290
    Patrice
    Aug 17, 2004
Loading...

Share This Page