kandi X-RAY | EffectiveJava Summary
kandi X-RAY | EffectiveJava Summary
EffectiveJava
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Prints the example
- Returns the maximum size of the given names
- Checks that the name starts with the given prefix
- Print the total number of characters
- Converts a list of names to upper case
- Print a collection
- Join a list of strings
- Filter multiple predicate with function function
- Filter multiple predicates
- This method prints the length of the given names
- Filter a list of names
- Print all characters
- Determines the maximum of the given names
- Find first first name
- Filter with the given names
- Print length with function name
- Use the comparator to sort the names
- Main method
EffectiveJava Key Features
EffectiveJava Examples and Code Snippets
Community Discussions
Trending Discussions on EffectiveJava
QUESTION
I am trying to fix double checked locking with Bloch's effective java recommendation. But a small variation in my code is that the field type is static and the method to create the field type is instance method. Will the below variation for creating a static field work?
...ANSWER
Answered 2021-Jan-20 at 23:59Assuming you are using Java 5 or later1, the above code is thread-safe2.
It doesn't matter that either the method or field is static
provided that:
- field being initialized is
volatile
and, - the code doing the DCL initialization is using the same mutex object for any given field.
The former is obviously true. The latter is true because all calls to getField4()
are locking the same Class
object.
1 - Prior to Java 5, the specified semantics of volatile
are not sufficient to guarantee that the code is thread-safe.
2 - Thread-safe but ugly. It is better to avoid the DCL idiom and use one of the other alternatives.
I cannot make the method static method ...
I don't see why not. It is private
so you should not be constrained as to whether it is a static or instance method. It should only affect the current class.
But as noted above, it doesn't make any difference to the idiom.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install EffectiveJava
You can use EffectiveJava like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the EffectiveJava component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page