Questions tagged [atomic-long]

Anything related to the Java `AtomicLong` data type, an integer type that can be accessed and updated atomically.

Anything related to the Java AtomicLong data type, an integer type that can be accessed and updated atomically.

See Java API AtomicLong documentation.

21 questions
1
vote
1 answer

LongAdder[] + System.arraycopy() =?

The simplified scenario is that I have an array of LongAdders and multiple threads are accessing this array in order to increment variable at a given index. Is it safe to arraycopy without any additional locking mechanism? As far as I've…
zerocool
  • 103
  • 1
  • 7
0
votes
2 answers

AtomicLong.set vs LongAccumulator.accumulate performance java?

I have a use case for high concurrent writes to an AtomicLong variable. I just need to set current epoc time in this variable. What would be the fastest way to do so? Is LongAccumulator.accumulate a better alternative to AtomicLong.set, are there…
Manas Saxena
  • 2,171
  • 6
  • 39
  • 58
0
votes
0 answers

Does AtomicLong's compareAndSet ensure threadsafety

This is in continuation to my previous question - Refactoring synchronization blocks keeping ordering of execution intact I have a synchronized block in one the functions which I want to do away with, having something else to reduce contention and…
deGee
  • 781
  • 1
  • 16
  • 34
0
votes
1 answer

Does Hazelcast getAtomicLong always generate a unique value?

I want to generate sequence values starting from a certain value in Mongodb.Instead, I've generated sequence values using hazelcast AtomicLong.However, when saving mongodb data, I get a duplicate key error.What would be the reason?
omerstack
  • 535
  • 9
  • 23
0
votes
0 answers

Spark Streaming: Average of all the time

I wrote a Spark Streaming application which receives temperature values and calculates the average temperature of all time. For that i used the JavaPairDStream.updateStateByKey transaction to calculate it per device (separated by the Pair's key).…
D. Müller
  • 3,336
  • 4
  • 36
  • 84
-1
votes
1 answer

AtomicLong concurrency output not as expected

I was running the following example, expecting the output to be 1000 always but I get 999 sometimes as well. I believe the output should always be 1000 or am I missing something here? public class AtomicTest { public static void main(String[]…
Adithya
  • 2,923
  • 5
  • 33
  • 47
1
2