multithreading - Java - synchronize individual elements in primitive array -


I have an array of so many ints, and I'm writing it a bit everywhere to store information . Similarly:

  public class myclass {int [] bitArray; // ways myclass public (bitArray = new int [200000000]; // 200 million ints} Public Zero Flag Bit (Int. Head index, Bit Index) {/ ** 10000000 00000000 00000000 00000000 & gt; & Gt; & Gt; Bit index * / bitaray [arrayindex] | = (0x80000000 & gt; gt; & gt; Beatindex); }}  

Now, as you can see, this is a lot of data. So efficiency is important.

However, I want to write data on this array in multiple threads (secured) at a time, unfortunately in Java, you can not do the following:

  public zero Flag bits (int. Head index, bitindex) {/ ** 10000000 0000000000000000000000 & gt; & Gt; & Gt; Bit index * / synchronize (bitaray [array index]) // wrong !!! The object must be synchronized! {Bitaray [array index] | = (0x80000000 & gt; & gt; BTIDX); }}  

So, I was wondering what is the most effective or best way to do this? I am aware of AtomicIntegerArray, but I believe I can be more efficient than that. I have tried to come up with a solution and this is what I have found (I have not tested it yet, though it is valid?)

  public class myclass {int [ ] BitArray; SYNC [] indexSync; // Internal orbit (SS) Private Static Final Class Sync {Private Static Finale Boolean Sync = Falls; } // methods public myclass () {bitArray = new int [200000000]; // 200 million ints indexSync = new sync [bitArray.length]; } Public Zero ValveBit (Int. Sir Index, Bit Index) {/ ** 10000000 00000000 00000000 00000000 & gt; & Gt; & Gt; Bit index * / synchronize (indexccc [arrayindex]) {bitaray [arrayindex] | = (0x80000000 & gt; & gt; BTIDX); }}}  

So, is there a more effective way of doing this in the manner I am posting? Is the way I've also posted work? Will my journey be very efficient? Thank you

You probably should only use AtomicIntegerArray. It seems as if the code written by experts is exactly what you need and thoroughly tested. You should check its performance before giving it a discount.

If you do not really want to use AtomicIntegerArray, then you do not really need the SYNC class, you can just use the Boolean object. Apart from this, if you are going to create a whole second array of sync objects, then it may be able to make inputs instead of your first entry inters.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -