Tag: race condition

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.

Continue reading

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.

Continue reading

© 2017 Brewing Codes

Theme by Anders NorenUp ↑