Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Question on multi-thread execute the same method of same classinstance (http://www.velocityreviews.com/forums/t602506-question-on-multi-thread-execute-the-same-method-of-same-classinstance.html)

QQ 03-28-2008 10:47 AM

Question on multi-thread execute the same method of same classinstance
 
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 03-28-2008 11:06 AM

Re: Question on multi-thread execute the same method of same classinstance
 
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 <chaojiang...@gmail.com> 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



Matt Humphrey 03-28-2008 11:30 AM

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

"Stefano Brocchi" <stefano.brocchi@researchandtechnology.net> wrote in
message
news:a780fefa-37a3-4291-bc48-0cec37552680@b64g2000hsa.googlegroups.com...
> 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/



stevenjiang.au@gmail.com 03-28-2008 12:08 PM

Re: Question on multi-thread execute the same method of same classinstance
 
On Mar 28, 10:06 pm, Stefano Brocchi
<stefano.broc...@researchandtechnology.net> 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 <chaojiang...@gmail.com> 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.

stevenjiang.au@gmail.com 03-28-2008 12:09 PM

Re: Question on multi-thread execute the same method of same classinstance
 
On Mar 28, 10:30 pm, "Matt Humphrey" <ma...@iviz.com> wrote:
> "Stefano Brocchi" <stefano.broc...@researchandtechnology.net> wrote in
> messagenews:a780fefa-37a3-4291-bc48-0cec37552680@b64g2000hsa.googlegroups.com...
>
> > 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.

Lew 03-28-2008 12:27 PM

Re: Question on multi-thread execute the same method of same classinstance
 
stevenjiang.au@gmail.com 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

Roedy Green 03-28-2008 02:56 PM

Re: Question on multi-thread execute the same method of same class instance
 
On Fri, 28 Mar 2008 03:47:00 -0700 (PDT), QQ <chaojiang.au@gmail.com>
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


All times are GMT. The time now is 02:13 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.