Home United States USA — software Introduction to Reflectionless: Discover the New Trend in the Java World

Introduction to Reflectionless: Discover the New Trend in the Java World

208
0
SHARE

Discover this new movement in Java frameworks that aim to circumvent the disuse of reflection to decrease application startup and decrease memory consumption.
Join the DZone community and get the full member experience. Over the last twenty-five years, many things have changed alongside new versions of Java, such as architectural decisions and their requirements. Currently, there is the factor of cloud computing that, in general, requires the application to have a better startup in addition to a low heap of initial memory. It is necessary to redesign the way the frameworks are made, getting rid of the bottleneck with reflection. The purpose of this article is to present some of the solutions that help reflectionless, the trade-offs of that choice, in addition to presenting the Java Annotation Processor. Within the framework, reflection certainly plays a big role in several tools, both for classic ORMs and other points, such as a REST API like JAX-RS. This type of mechanism makes life easier for the Java developer by massively reducing various operations’ boilerplate. Some people report that the Java world’s biggest difference is precisely the many tools and ecosystems around the language. For the end-user, and here I mean the user who uses these frameworks, this whole process happens in a magical way. Just put some notations into the class, and all operations will work perfectly. They or the class metadata will be read and used to facilitate some process. Currently, the most popular way to perform this type of reading is from the reflection that performs an introspection that lightly generates an idea of dynamic language within Java. The use of the reflection API for this type of work within the framework was made easier due to the great material created, with examples and documentation for this type of work. However, there are some problems like the one said at the time of startup and the consumption of memory, for some reasons that we will discuss. The first reason is that all processing and data structure will be performed at the time of execution. Imagine a dependency injection engine that needs to scan class by class, check scope, dependencies, and more. Thus, the more classes that need to be analyzed, the more processing is required and tends to increase the response time. A second point is in memory consumption, one of the reasons related to the fact that each class needs to be traversed to search for metadata within the Class, that there is a ReflectionData cache that loads all the information of the class, that is, to search for simple information, such as getSimpleName(), all the metadata information is loaded and referenced through the SoftReference that takes time to get out of memory. In summary, the reflection approach poses a problem both in the initial memory consumption and in the delay in starting the application.

Continue reading...