Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: CounterLocalService does not work properly.
Hi
I'm ali and try to understand how counter is working.
As i undertood, counter increment a varialble and retrive value. by default its increment one by one. but we can change step. problem is here. i increase counter number to 80 and at next a call increment method with size =70. basically i should get 150 but in practice i get 180.
i shared my codes on github
https://github.com/a-forghani-y79/7.3ga8
liferay version : 7.3ga8
Hi,
The next step is calculated from the last incremented value saved in memory and not the size which is in DB, so you may need reset the counter completely and then set the size as below .
counterLocalService.reset(name);
counterLocalService.reset(name, 80);
counterLocalService.increment(name, 70);
You are getting 180 instead of 150 is because the counter value saved in memory may be 110
You're linking to a full repository with multiple modules, and probably refer to some random class in there.
Please condense your code so much that you can include it in the question, describe the expected vs actual outcome. It's a lot of work to figure out what you do/see/expect otherwise, and you probably want to make answering as easy as possible...
hi
if i explain it in simple way:
1- try to deploy module that incloude this component:
so we except this output:
- hi its a test
- new value: 1
- new value: 10
- new value: 80
- new value: 130
-end
but actually we got this:
- hi its a test
- new value: 1
- new value: 10
- new value: 80
- new value: 150
-end
may be liferay has some special mathemathic rules. but as i know 50+80 equals 130. its NOT 150.
As the counter, by default uses 100 as increment count for DB update , once your incremented value crosses 100 it will create new set of counter values. This is the reason why your getting 150 instead of 130.
If you need contineous counter you can set below value in your portal-ext.properties file.
counter.increment.[$COUNTER_NAME$]=1
In your case,you can use
counter.increment.test=1
Powered by Liferay™