I felt the need for lazy initialization in custom appender and started to look at options.
In this blog i will share things that i tried.
One of the thing that came to my mind was Singleton approach but now it is known fact that singleton causes problem with testing and make it impossible to extend it, so approach of mixing concurrency & object construction is not that good.
Incase if singleton is required then it is better to use Dependency Injection framework rather than spoiling your application code.
Lets get back to lazy initialization/eval.
Some programming language like scala/swift etc has support for lazy, so no custom code is required to do this but in java space we still have to write thread safe code to get it right.
Lets look at some options we have in java and what type of performance we get.
- Brute force using Synchronized
This is the most simple and inefficient one, scala is using this approach. Scala one is available @ ScalaLazy.java
- Double lock
This is little complex to write and gives good performance.
- Using Future task
This approach is simple to write and gives good performance.
Double lock approach gives the best performance and brute force one is worst. I did quick bench mark for 1 Million calls using different number of thread.
Single lock performance is very bad, lets have look at the number by removing single lock to see how Double Lock & Future Task performed.
These benchmark are done very quickly but detailed benchmark numbers should be close.
Code for this blog post is available @ github
|
Superb, I really enjoyed very much while reading this article. Really it is an amazing article. I had ever read like this article. I hope it will be very helpful for all. Thank you so much for this amazing article and please keep update like this excellent post. Thank you for sharing such a great article with us.
ReplyDeleteEngineering Colleges in Chennai, Mechanical Engineering Colleges in Chennai
This is a valuable and timely discussion on AI Document Verification Portal Development, especially as businesses face growing risks from fake IDs, altered documents, and identity fraud. AI-powered verification portals can make the checking process faster by combining OCR, facial recognition, document analysis, liveness detection, and fraud detection into one workflow. This can be particularly useful for fintech companies, banks, insurance providers, marketplaces, and other platforms that need reliable user verification.
ReplyDeleteWhat I find most interesting is how these solutions can reduce manual document checks while maintaining a strong focus on accuracy and security. A well-developed verification portal can also support multiple document types, automated validation, real-time checks, and integration with existing onboarding systems. However, businesses should also consider data privacy, regulatory requirements, scalability, and the quality of AI models when selecting a development partner.
For companies planning to build or upgrade their verification platform, exploring experienced development agencies can help identify the right technical approach and feature set. The detailed list of agencies provides a useful starting point for comparing capabilities and finding a suitable technology partner.
The discussion around AI Document Verification Portal Development is especially relevant for businesses looking to create faster and more dependable digital onboarding experiences. Companies such as HourlyDeveloper can be considered when evaluating development expertise for AI-powered solutions.
Overall, this is a useful resource for anyone researching AI-based document verification and planning their next digital identity project.
This is a fascinating post about Spark microservices! Combining Apache Spark's big data processing capabilities with microservices architecture is a powerful approach for scalable data applications. Your insights into this integration are valuable for data engineers and architects. For those interested in big data and AI, I've been exploring Gen AI and Agentic AI online training in Electronic City to understand how AI is being applied to big data architectures. Thanks for sharing this technical insight!
ReplyDelete