Tags / Java
Using StringBuilder instead of usual concatenation. When is it appropriate?
You might know that using string concatenation in Java is not a good practice as it might affect performance. In this short article, I will try to describe when it is necessary to use StringBuilder and when we can afford using concatenation (+ sign). Let's start with a simple example: To see how it works under the hood…
My plans for the future
Update 06.02.2021: still getting there and changing my plans according to the situation :)
Logging in ATG: how to send error reports to Elasticsearch and display them with Kibana
In this article, I'm going to share my experience with Oracle ATG logging system and such great tools like Elasticsearch and Kibana. Imagine that we have a big ATG-based project and our task is to store and list all the users who met (explicitly or not) errors. To solve this task we will add a new event listener to…
Using one DateFormat instance per thread with ThreadLocal
Here is a quick tip how to use DateFormat inside a ThreadLocal field. Why do we need that? The reason is the DateFormat class is not thread-safe but creating its instances is an expensive operation. So, this is kind of a workaround that creates only one instance of DateFormat per thread.
UnhandledExceptionHandler in Java: how to catch uncaught exceptions
In this short tutorial, I'm going to describe how to handle uncaught exceptions in threads. This can be done by: Using threadInstance.setUncaughtExceptionHandler() ─ for a specific thread Overriding ThreadGroup's uncaughtException() method ─ for a thread group Using Thread.setDefaultUncaughtExceptionHandler() ─ for all…
How to lookup a user profile from a global-scoped ATG component
This article describes how to look up a session-scoped user profile component from a global scope component that has no access to a DynamoHttpServletRequest object. To achieve this functionality, we will use a ThreadLocal field an ATG feature called Insertable Servlet . When a request object is created, it goes…
How to run a Groovy script from Java
One of the ways of running a Groovy script from Java is using GroovieShell. First, add the groovy-all Maven dependency (consider using a fresher version): Next, create a class containing the main method. The Binding instance helps us to bind variables to the shell. These variables will be available for our script. We…