• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Static Method Simultaneous and Multi-Thread

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have never thought about this regarding multi-thread and the static elements until now, but here it is:

I know that Static Methods are on the Heap while Threads on are on the Stack...

However, if we have two threads running - all accessing the same Static Method. Can the Static Method be executed AT THE EXACT SAME TIME by both Threads or is there usually an order of it depends which Thread (say for example Thread 1) - reaches that Static Method first - and the other (say - Thread 2) - can only execute using that same Static Method only once Thread 1 finishes using it?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Perry Terrance wrote:I know that Static Methods are on the Heap while Threads on are on the Stack...


They are? I thought all methods were defined only once, so it seems unlikely.

What is possible is that Thread objects are held in a stack of some kind - although it seems more likely that it would be a processing stack, not a memory one.

Can the Static Method be executed AT THE EXACT SAME TIME by both Threads or is there usually an order of it depends which Thread (say for example Thread 1) - reaches that Static Method first - and the other (say - Thread 2) - can only execute using that same Static Method only once Thread 1 finishes using it?


No, because if that was the case then you wouldn't have to synchronize static methods, would you? And you do.

The main difference between static methods and instance ones, AFAIK, is that the latter have an implicit this parameter. Other than that, they're just code.

HIH

Winston
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic