You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2020/02/19 09:39:03 UTC

[GitHub] [rocketmq] rushsky518 opened a new issue #1780: question about ReferenceResource#hold

rushsky518 opened a new issue #1780: question about ReferenceResource#hold
URL: https://github.com/apache/rocketmq/issues/1780
 
 
   ````java
       protected final AtomicLong refCount = new AtomicLong(1);
       public synchronized boolean hold() {
           if (this.isAvailable()) {
               if (this.refCount.getAndIncrement() > 0) {
                   return true;
               } else {
                   this.refCount.getAndDecrement();
               }
           }
   
           return false;
       }
   ````
   refCount is already AtomicLong type, is it necessary to put `hold` method in a synchronized block

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [rocketmq] RongtongJin commented on issue #1780: question about ReferenceResource#hold

Posted by GitBox <gi...@apache.org>.
RongtongJin commented on issue #1780: question about ReferenceResource#hold
URL: https://github.com/apache/rocketmq/issues/1780#issuecomment-592351970
 
 
   IMO, it is neccessary to add `synchronized`, hold method must be mutually exclusive with the synchronized block below. Otherwise, it is possible that hold returns true and cleanup success.
   https://github.com/apache/rocketmq/blob/73bb4b402a5da02faf9feded8f4d79dd1ba88348/store/src/main/java/org/apache/rocketmq/store/ReferenceResource.java#L56-L65
   In addition, issue is for bug report and feature request, so welcome to ask question on [mail list](http://rocketmq.apache.org/about/contact/).

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [rocketmq] RongtongJin closed issue #1780: question about ReferenceResource#hold

Posted by GitBox <gi...@apache.org>.
RongtongJin closed issue #1780: question about ReferenceResource#hold
URL: https://github.com/apache/rocketmq/issues/1780
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services