Because your threads are blocking my performance.

Spools of multi-colored thread
Spools of multi-colored thread
Image by Vesna Harni from Pixabay

Non-Blocking I/O has been around for a while. Different languages implement it differently, but all provide a way to reduce the thread count while seeming to allow full concurrency. JavaScript has been doing it from the start; with only one thread, you better not be the coder that pushes a blocking call into production.

While reactive Java is gaining some traction, most Java coders I know still live in a multi-threaded frame of mind. Why? Threads are a relatively easy concept to grasp. Reactive Java requires us to rethink a lot of how we learned to code. …

A Java implementation for users and miners

Man using drill
Man using drill
Photo by James Kovin on Unsplash.

Cryptocurrency mining is probably a misnomer and results in some misunderstanding about what miners do. Mining usually evokes an image of extracting something, but with cryptocurrency mining, the miners are building the blockchain and getting paid to do it. Miners race to gather all new transactions, put them in a block, and provide some artificial proof of work.

This is the third and final part of my series on the blockchain in which I will implement users and miners to my collection of Java services. I already implemented part of the mining work because you can’t have a blockchain without…

Trust via peer-to-peer networking

Spider web
Spider web
Image by ClaudiaWollesen from Pixabay

In the first part of this series, we made a single blockchain. Now we’re going to make a set of them and get them talking to one another. The real point of the blockchain is a distributed system of verification. You can add blocks from any nodes and eventually it gets to peer nodes so everyone agrees on what the blockchain looks like. This is important because you don’t want a single source of truth in a distributed system.

There is one problem that comes up right away: Each node is two services, plus a MongoDB and a Kafka message…

A simple explanation without the hype

Some prop coins that have come to represent Bitcoin
Some prop coins that have come to represent Bitcoin
Image by MichaelWuensch from Pixabay

Once again, cryptocurrencies are in the news everywhere. Are you still struggling with what cryptocurrencies are? Don’t worry, we all are. No one knows what to make of them or even how to value them. That’s why when you watch the crypto markets, you’ll get dizzy watching them go up and down so fast. We’re in a discovery process, where a market tries to come to a consensus on valuation.

Disclosure: I work for a company that enables you to buy Bitcoin.

Bitcoin was invented in 2009. The financial markets were in a tail-spin, and the U.S. was printing dollars…

Unchaining the blockchain

A chain
A chain
Image by analogicus from Pixabay

I get a lot of questions about cryptocurrencies and their underlying mechanism, the blockchain. A lot of the time I have trouble explaining it succinctly, so I’m going to write a blockchain example to better understand it myself. This article is one of three that will talk about the constituent parts: the chain of blocks, peer-to-peer networking, and mining. I won’t be making a cryptocurrency from it, just the blockchain with some abstract unit of value.

Not trying to make a true cryptocurrency simplifies a number of things. There are no fees or rewards (mining is done for the pure…

Despite all his flaws, Walt wanted a better future for everyone.

Photo by Randal Kamradt

As a child of Southern California, Disneyland was a yearly staple for me and my family. I have many memories of the magic that Disney conjured for the world. His was a vision of a better world; clean, organized, fun, and exciting.

Of course, his vision was shaded by a white European mindset. His Jungle Cruise was a Conradesque vision of a trek through Africa. It’s being cleaned up now, but it’s still white culture depicting black culture. If there was ever a black Disneyland, it would probably be a complete shock to white visitors. …

Good practices in asynchronous programming

Traffic at night
Traffic at night
Image by John Howard from Pixabay

The key to reactive programming is to react. You don’t say “do this now,” you say “do this when.” The “when” applies to when you have work to do. The work comes to you as events: a message on a message bus or an HTTP request.

First, I should explain the reason reactive programming is important. One of the benefits of Java is relatively easy threading. That has made threads the predominant model for handling events. When you get an event, you dispatch a thread to handle it. The problem is when you get a lot of events, you wind…

Conjuring functions from thin air

photo of a lamb
photo of a lamb
Image by Anja🤗#helpinghands #solidarity#stays healthy🙏 from Pixabay

I seem to spend a lot of time explaining Java functional programming. Really, there’s no magic here. You pass functions into functions to adapt their behavior. Why would you want to do that? If you’re using object-oriented development, you’re already doing it but in a very controlled fashion. Java’s polymorphism is implemented by keeping a list of functions that can be replaced by sub-classing. Then other functions of that class might call a function that has been overridden, and thus its behavior is changed even though the outer function wasn’t itself overridden.

Let’s take an example of polymorphism and translate…

Don’t bring your JavaScript code smells to Java

Photo by Nour Wageh on Unsplash.

JavaScript coders recognize the deeply nested callbacks that were the original way of dealing with asynchronous code and have given it a name. Since JavaScript only has a single thread, blocking is a no-no, so any code that has I/O needed to have a function that would be called when the request was finished. So you would have code like this:

This is the most straightforward way of writing code when the blocking methods all take a function as a parameter, but reading it can give you a headache. If the code gets too wide, it scrolls off the…

Using an orchestration orchestrator

Conductor Andrea Vitello
Conductor Andrea Vitello
Image by artesitalia from Pixabay

In my previous article Running Java Microservices in Kubernetes, I created a set of deployment files for some example microservices that I created. Today I’m going to automate deploying them using ArgoCD. Argo will take a directory filled with deployment files and not only deploy them but give you some visibility into them.

To install Argo, I used their instructions with a few minor modifications. My commands were:

kubectl create namespace argocd
kubectl apply -n argocd -f \
brew install argocd
kubectl port-forward svc/argocd-server -n argocd 8080:443

This will expose the UI at port 8080, so you can browse…

Randal Kamradt Sr

Software dev for thirty years still keeping on top of the latest tech trends. I write about the learning process.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store