Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
QQ - 28 Mar 2008 11:47 GMT
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 - 28 Mar 2008 12:06 GMT
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

> Hi all
>
[quoted text clipped - 5 lines]
>
> Steven
Matt Humphrey - 28 Mar 2008 12:30 GMT
> 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 - 28 Mar 2008 13:09 GMT
> > Hi,
>
[quoted text clipped - 8 lines]
>
> Matthew Humphreyhttp://www.iviz.com/
Thank you very much for that.
stevenjiang.au@gmail.com - 28 Mar 2008 13:08 GMT
On Mar 28, 10:06 pm, Stefano Brocchi
<stefano.broc...@researchandtechnology.net> wrote:
> Hi,
>
[quoted text clipped - 15 lines]
>
> > Steven

Thank you very much.
Lew - 28 Mar 2008 13:27 GMT
> 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.

Signature

Lew

Roedy Green - 28 Mar 2008 15:56 GMT
>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
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.