Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiple Threads accessing at a time  RSS feed

 
rakesh kumar nampally
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Sorry if i post this question at the wrong place.

Everyone ask if two methods access the same method at the same time what will you do. At this point generally we speak about synchronized methods.

My question is in an enterprise application every request comes in like a individual thread, and every thread maitains there individual stack, then there should be no problems with local or member variables declared in that method, even the two threads access the same method at a time, where does situation occur where we use synchronized methods.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem arises if the two threads call a method of the same object. That object only exists once, so any static and instance variables of that object are at risk.
 
Sachin Joshi
Ranch Hand
Posts: 83
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These type of questions can be understood only by trying out a few thread based code, and playing around with it. Try writing some test code and do see if things work as you expect.

Here are few Thread Example code which should give you more understanding on threading and synchronization.

Try to create such small programs and if in doubt ask questions on the behavior of those programs. This will enable people to answer more specific questions for you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!