Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Question on multi-thread execute the same method of same classinstance

Reply
Thread Tools

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

 
 
QQ
Guest
Posts: n/a
 
      03-28-2008
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
 
Reply With Quote
 
 
 
 
Stefano Brocchi
Guest
Posts: n/a
 
      03-28-2008
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 <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
 
Matt Humphrey
Guest
Posts: n/a
 
      03-28-2008

"Stefano Brocchi" <(E-Mail Removed)> wrote in
message
news:(E-Mail Removed)...
> 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/


 
Reply With Quote
 
stevenjiang.au@gmail.com
Guest
Posts: n/a
 
      03-28-2008
On Mar 28, 10:06 pm, Stefano Brocchi
<(E-Mail Removed)> 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 <(E-Mail Removed)> 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.
 
Reply With Quote
 
stevenjiang.au@gmail.com
Guest
Posts: n/a
 
      03-28-2008
On Mar 28, 10:30 pm, "Matt Humphrey" <(E-Mail Removed)> wrote:
> "Stefano Brocchi" <(E-Mail Removed)> wrote in
> messagenews:(E-Mail Removed)...
>
> > 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.
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      03-28-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      03-28-2008
On Fri, 28 Mar 2008 03:47:00 -0700 (PDT), QQ <(E-Mail Removed)>
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
method def in method vs method def in block Kyung won Cheon Ruby 0 11-21-2008 08:48 AM
calling a method with 'throws IOException' from another method in the same class rleroux@telus.net Java 1 01-28-2007 06:30 AM
tell other thread to execute method roni ASP .Net 2 04-12-2005 08:53 AM
Error occuring when i execute Fire method of BaseEvent Class =?Utf-8?B?TmlzaGVldGggS2F1c2hhbA==?= ASP .Net 0 12-07-2004 02:05 PM
Can i execute aspx file in my asp pag with server.execute method(sorry) Savas Ates ASP General 1 08-17-2004 04:52 PM



Advertisments