O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

There's more...

In our examples, we used very simple code. If more complexity is added to any of the methods, especially with parameters (and especially when some of the parameters are objects), it is possible you'll get concurrency issues again:

int getSomething(AnotherMutableClass amc, String whatever){  //... code is here that generates a value "whatever"   amc.setProperty(whatever);  //...some other code that generates another value "val"  amc.setAnotherProperty(val);  return amc.getIntValue();}

Even if this method belongs to ImmutableClass and does not affect the state of the ImmutableClass object, it is still a subject of the thread's race and has to be analyzed and protected as needed.

The Collections class has methods that make various ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required