Hey so I’m wondering how can I make AtomicInteger a two dimensional array, From what I’ve found on javadocs AtomicIntegerArray is only single dimension.
int[] newArray = new int[100];
AtomicIntegerArray atomicarray = new AtomicIntegerArray(newArray);
Which creates a AtomicIntegerArray of size 100. But I would like an atomicarray with two dimensions. I’ve tried doing..
AtomicInteger[][] atomicArray = new AtomicInteger[100][100];
atomicArray[00][00].set(1);
But I am met with..
java.lang.NullPointerException at nz.ac.massey.threadpool.MyClass.(MyClass.java:20)
So any ideas? thanks! :)… I haven’t done much work with Atomic variables before.
if this isn’t possible how can I minimic a regular primitive integer two dim array into a AtomicInteger two dim array?
You need to instantiate all of the positions in the matrix before accessing them, something like this:
Or this, if you want to initialize each atomic integer in a certain initial value:
That, for all
i,jpositions in the matrix. Normally you’d do this using a couple of nestedforloops: