Skip to content

Brewing Codes Posts

Java’s Synchronized Keyword in Three Minutes

I wrote this article for SitePoint’s Java channel, where you can find a lot of interesting articles about our programming language. Check it out!

The synchronized keyword can be used to ensure that only one thread at a time executes a particular section of code.
This is a simple way to prevent race conditions, which occur when several threads change shared data at the same time in a way that leads to incorrect results.
With synchronized either entire methods or selected blocks can be single-threaded.

This article requires basic knowledge of Java threads and race conditions.

Leave a Comment

The Dangers of Race Conditions in Five Minutes

I wrote this article for SitePoint’s Java channel, where you can find a lot of interesting articles about our programming language. Check it out!

A race condition is an undesired property of multithreaded code.
It expresses that the program’s outcome depends on a particular order of operations but that the underlying platform (in the case of Java, the JVM) does not guarantee that order.
As a consequence the outcome is often fluctuating across runs as it depends on how exactly operations from different threads interleave.
In Java, race conditions occur most often when multiple threads share and mutate the same object.

The only prerequisite for this article is a basic knowledge of threads.

Leave a Comment

Java Thread Class in Five Minutes

I wrote this article for SitePoint’s Java channel, where you can find a lot of interesting articles about our programming language. Check it out!

In a running Java program, all code is executed in threads and within a thread everything happens sequentially, one instruction after another.
When Java (or rather the JVM) launches, it creates one thread for the main method to be executed in.
From there, new threads can be created to execute code in parallel to the main one.
The most basic way to do that is to use the Thread class.

This article does not require any knowledge of multithreaded programming, but you need to be familiar with core Java concepts such as classes and interfaces.

Leave a Comment

Beyond POJOs – Ten More Ways to Reduce Boilerplate with Lombok

I wrote this article for SitePoint’s Java channel, where you can find a lot of interesting articles about our programming language. Check it out!

Lombok is a great library and its main selling point is how it declutters POJO definitions.
But it is not limited to that use case!
In this article, I will show you six stable and four experimental Lombok features that can make your Java code even cleaner.
They cover many different topics, from logging to accessors and from null safety to utility classes.
But they all have one thing in common: reducing boilerplate to make code easier to read and more expressive.

Leave a Comment

Distributed graphs processing with Pregel

Graphs processing is an important part of data analysis in many domains. But graphs processing is tricky may be tricky since general purpose distributed computing tools are not suited for graphs processing.

It is not surprising that an important advancement in the area of distributed graphs processing came from Google that has to process one of the biggest graphs: the Webgraph. Engineers in Google wrote a seminal paper where they described a new system for distributed graphs processing they called Pregel.

In this article, I will explain how Pregel works, and demonstrate how to implement algorithms using Pregel using API from Apache Flink.

Leave a Comment

Declutter Your POJOs with Lombok

I wrote this article for SitePoint’s Java channel, where you can find a lot of interesting articles about our programming language. Check it out!

I have a love/hate relationship with Java.
On one hand, it’s a mature programming language with a diverse number of frameworks and libraries that make development relatively easy.
On the other hand, it’s very verbose and requires writing massive amounts of boilerplate code for common tasks.
The situation got better with the introduction of lambdas and streams in Java 8, but it is still sub-par in some areas, like writing plain old Java objects POJO.
In this post, I’ll show you how to rewrite POJOs in only a few lines of code with Lombok.

Leave a Comment

Graphs processing with Apache Flink

Graphs are everywhere. Internet, maps, and social networks to name just a few are all examples of massive graphs that contains vast amounts of useful information. Since the size of these networks is growing and processing them become more and more ubiquitous, we need better tools to do the job.

In this article, I’ll describe how we can use Flink Gelly library to process large graphs and will provide the simple example of how we can find a shortest path between two users in the Twitter graph.

Leave a Comment

Implementing Flink batch data connector

Apache Flink has a versatile set of connectors for externals data sources. It can read and write data from databases, local and distributed file systems. However, sometimes what Flink provides is not enough, and we need to read some uncommon data format.

In this article, I will show you how to implement a custom connector for reading a dataset in Flink.

Leave a Comment

Using Apache Flink with Java 8

JDK 8 has introduced a lot of long-anticipated features to Java language. Among those, the most notable was the introduction of lambda functions. They allowed adding new frameworks such as Java 8 Streams, as well as, new features to existing frameworks like JUnit 5.

Apache Flink also supports lambda functions, and in this post, I’ll show how to enable them and how to use them in your applications.

Leave a Comment

Calculating movies ratings distribution with Apache Flink

If you’ve been following recent news in the Big Data world, you’ve probably heard about Apache Flink. This platform for batch and stream processing, which is built on a few significant technical innovations, can become a real game changer and it is starting to compete with existing products like Apache Spark.

In this post, I would like to show how to implement a simple batch processing algorithm using Apache Flink. We will work with a dataset of movie ratings and will produce a distribution of user ratings. In the process, I’ll show few tricks that you can use to improve the performance of your Flink applications.

Leave a Comment