Home » Archives for Ashraf Sarhan » Page 2

Author Archives: Ashraf Sarhan

Ashraf Sarhan is a passionate software engineer, an open source enthusiast, has a Bsc. degree in Computer and Information Systems from Alexandria University. He is experienced in building large, scalable and distributed enterprise applications/service in multiple domains. He also has a keen interest in JavaEE, SOA, Agile and Big Data technologies.

Drawing Swing JTable rows with different colors using TableCellRenderer interface Example

In this example we are going to demonstrate how to use Java Swing TableCellRenderer interface to customize cell rendering. When a JTable object is created, several default renderers are also created. Those renderers are capable of rendering Boolean choices, dates, image icons, numbers, and objects (as strings). If you do not explicitly attach a custom render to a column, a ...

Read More »

Loading environment specific configurations and properties with Spring using Maven Profiles and Settings Example

In this example we shall show you how to load specific environment configurations and properties with Spring using Maven POM Profiles and XML Settings. Our previous example, shows how to load specific environment configurations and properties using Spring where these properties files are located inside the project resource folder. However, sometimes we have a sensitive authentication information like database user name, passwords, etc., and uploading ...

Read More »

Reloadable properties file with Spring using Apache Commons Configuration

In this example we shall show you how to create an auto-reloadable application properties file with Spring using Apache Commons Configuration. Our previous example, shows how to load specific environment configurations and properties using Spring. However, when we make some changes in the properties files, we have to rebuild and redeploy our application again. Although, this approach doesn’t fit all ...

Read More »

Load environment configurations and properties with Spring Example

In this example we shall show you how to load specific environment configurations and properties using Spring. Since version 3.1, Spring support an environment aware feature called profiles. Now we can activate profiles in our application, which allows us to define specific configurations beans and properties by deployment regions, such as “development”, “testing” and “production”, etc. Let’s start our example ...

Read More »

org.apache.commons.dbcp2.BasicDataSource Example

In this example we shall show you how to make use of BasicDataSource class of Apache Commons DBCP. Nowadays, many web applications interacts with a relational database, Creating a new connection for each user can be time consuming (often requiring multiple seconds of clock time), in order to perform a database transaction that might take milliseconds. Opening a connection per ...

Read More »

java.util.concurrent.ThreadFactory Example

In this example we shall show you how to make use ThreadFactory interface, ThreadFactory is implemented by a user class to override its newThread() method for on-demand creation of a new thread with a specific configuration like thread name, type(user, daemon) and priority, etc.         ThreadFactory vs default ThreadFactory: In a typical Java ExecutorService application where some threads ...

Read More »

java.util.concurrent.ConcurrentNavigableMap Example

In this example we shall show you how to make use ConcurrentNavigableMap Interface, ConcurrentNavigableMap is a NavigableMap which provides navigation methods that returns the closest match for given search targets with a concurrent access support for its submaps. The submaps are the maps returned by various methods like headMap(K toKey), tailMap(K fromKey) and subMap(K fromKey, K toKey).       ConcurrentNavigableMap ...

Read More »

java.util.concurrent.atomic.AtomicLongArray Example

In this example we shall show you how to make use of AtomicLongArray class,  AtomicLongArray is a long array in which elements may be updated atomically. In a multithreading concurrent application architecture, we have a few tasks which are parallelized in such a way as to require no coordination between threads. The true problem comes when we need a coordination between ...

Read More »

org.apache.commons.io.monitor.FileAlterationMonitor Example

In this example we shall show you how to make use of FileAlterationMonitor class, FileAlterationMonitor comes from the FileMonitor API of the Commons IO library which provided by the Apache Foundation. It spawns a monitoring thread triggering any registered FileAlterationObserver at a specified interval. A FileAlterationObserver represents the state of files below a root directory, checking the filesystem and notifying FileAlterationListener of create, ...

Read More »

java.util.concurrent.RecursiveTask Example

In this example we shall show you how to make use of Java RecursiveTask class, RecursiveTask provides a convenient way to consolidate results from subtasks. Java 7 introduced another implementation of ExecutorService: the ForkJoinPool class. ForkJoinPool is designed for handling tasks efficiently that can be repeatedly broken down into subtasks, using the RecursiveAction class (when the task produces no result) or ...

Read More »