• 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
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Basic understanding for thread

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,

the question below was asked me in one of the interview.
And i just want to make sure if my understanding is correct or not.



Now here, if the Student class has 2 Threads of Same instance.

and call is made by them, say Thread1.getId() and Thread2.getSub()
Will it work ? Will both methods will get called ?

My understanding is, at a time one instance can have one lock.
But want to know how does it operate when we have 2 threads of same instance
for two different synchronized methods ?

Hope, i am clear with my question.
please let me know if you want further details on it.

Also, if any one can explain me in detail with sample,
how it works in polymorphism that would be awesome !!
My concepts of threads are weak, and i need some what more understanding in that !!

Thanks in Advance !!
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ved dixit wrote:
Now here, if the Student class has 2 Threads of Same instance.


How do you achieve this?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ved dixit wrote:


synchronized(this) void getSub(){} ? do you trying to execute this concept?

ved dixit wrote:
Now here, if the Student class has 2 Threads of Same instance.

and call is made by them, say Thread1.getId() and Thread2.getSub()
Will it work ? Will both methods will get called ?


since there is an only one instance, one thread will succeed and execute method. another thread have to wait to get the lock to enter another method which is also synchronized.

suppose each thread started in separate instance then every thread will get executed, since every thread has its own object lock.

hope this helps.
 
ved dixit
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Seetharaman : Thanks for the Response !!

You gave me the answer for the first query.
Can you give me some explanation if the same
thing can be apply with the polymorphism or not ?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic