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

ExecutorService and synchronization  RSS feed

 
john s murray
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm somewhat newbie here in trying to understand synchronization and threads. Here is an example of what I'm doing and want to get some inputs to see if that makes sense.

 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the use case that you posted, using synchronized run() and somethingElse() methods doesn't really make sense. The instances of the TestThreads class are created inside the loop, as part of the execute(...) method. References to those Oblects can't escape the execute method, and so can't really be accessed by multiple Threads. So there is no need to synchronize those Objects the way you did.
 
john s murray
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the clarification. had doubts as I still new to threads.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!