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

Q

QQ

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
 
S

Stefano Brocchi

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
 
M

Matt Humphrey

message
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/
 
S

stevenjiang.au

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

Thank you very much.
 
S

stevenjiang.au

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.
 
L

Lew

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.
 
R

Roedy Green

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top