This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Executor.execute( Runnable ) thread safety

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this method thread safe ? Pardon me if I'm asking a stupid question.
 
Paul Clapham
Sheriff
Pie
Posts: 20188
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Executor is an interface. So you are asking a question about all of the possible classes that might ever implement it. Besides, for each of them the question mostly boils down to whether the Runnable being executed is thread-safe. So I would say the answer is "Don't count on it."
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,

Assuming that all my Runnable(s) are thread-safe, then I gather from your answer that I will still need to synchronized access to invocations of Executor.execute( Runnable ). Thanks.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pho Tek:
Paul,

Assuming that all my Runnable(s) are thread-safe, then I gather from your answer that I will still need to synchronized access to invocations of Executor.execute( Runnable ). Thanks.


Executor.execute( Runnable ) is not a blocking call. It will execute your task sometime later. So, synchronized access to its invocation would not help.
I think if your Runnable instances are using shared resources and they are thread-safe then you do not need to worry about anything in the world but if they are not thread-safe and they are accessing shared resources then you should make them thread-safe. There is no middle-path
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic