java - Is it good practice to use AtomicInteger as a substitute for mutable Integer? -
I have the following scenario: This is a simple form of code that I'm showing here to explain my concern I: I know that this can be done by I do not think this is a good idea: in reference Using an array is not a good idea, even if it works technically well. The problem is that the resultant code is also not descriptive, in that sense the "mapping" of the indicators means its meaning (i.e. You will be better off with a multiplier class, which holds two properties: It receives a very good readability, creating a misconception that there is some concurrent running behind the scene. Public Zero Columns () {Atomic integer howohonobbs = NewElectricIntergrader (0); AtomicInteger howManyEvens = New AtomicInteger (0); loopthrough (100, howManyOdds, howManyEvens); System.out.println (howManyOdds.get () + "" + howManyEvens.get ()); } Private Zero Loopthu (Int counter, AtomicIntergeor howManyOdds, AtomicInteger howManyEvens) {for (int i = 1; i & lt; = counter; i ++) {if (M = 2 == 0) howManyEvens.get and Add (1) ; And how many people are there? Add and Add (1); }}
int [] but it looks strange. Is it a good option for a variable integer in atomic integers in such cases? If not then why?
AtomicInteger < Using / code> is not naturally concurrent, the reader is misleading.
0 -> strange,
1 -> gt; Even though) is not visible from the API itself.
public squares oddven {int strange, even; Public int getOdd () {odd return}} public int getEven () {return even;} public zero incOdd () {strange ++;} public zero incEven () {even ++;}}
Comments
Post a Comment