This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Is CountDownLatch Thread-Safe ?  RSS feed

 
Joe Fisher
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If Thread wants to getCount() and conditionally countDown(), does block need to be synchronized ? These methods are not sych'd according to java docs

Thanks.
 
Henry Wong
author
Sheriff
Posts: 23275
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes and no.... Yes, the countdown latch is thread safe and can be used by multiple threads. But no, the value return from getCount() is only valid til right before it returns. If you need to have data consistency between methods, you need to synchronize externally. (And this is true whether the individual methods are synchronized or not)

Henry
[ May 19, 2005: Message edited by: Henry Wong ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!