Game Instructions

Tap a tile to toggle its color. When a tile changes nearby tiles may change as well. Each move affect multiple tiles. The target is to turn all tiles into yellow in the fewest steps possible.

Press 'j' to show/hide the game. Press 'i' to show/hide the instructions. Press 't' to show/hide the top score table.

Steps: 0

Top Scores

Name Steps
Press J to toggle the game, I to toggle instructions, and T to toggle the top scores

Congratulations!

You solved the puzzle in 0 steps!

Success!

Score submitted successfully!

Error

Failed to submit score. Please try again.

ScopedValue in Java: Sharing Context Without ThreadLocal

Two Programmers
Java applications frequently need to make contextual information available across multiple method calls. Using ThreadLocal is one option. Using ScopedValue is an alternative.

ScopedValue became a permanent Java API in Java 25, after several preview iterations. It is part of the java.lang package.

Creating a ScopedValue Object

We can easily create a new ScopedValue object by calling the ScopedValue.newInstance() method.  Once the object was created we can easily attach it with key-value pairs. 

				
					private static final ScopedValue<String> car = ScopedValue.newInstance();
				
			

ScaopedValue Code Sample

The following code sample shows how easy it is to create a ScopedValue object and share a key-value pair across multiple function calls using the ScopedValue object we created. 

				
					public class ScopedValueDemo {
    private static final ScopedValue<String> USER = ScopedValue.newInstance();

    static void main() {
        ScopedValue.where(USER, "David").run(ScopedValueDemo::processRequest);
    }

    static void processRequest() {
        System.out.println("Processing request for " + USER.get());
        writeLog();
    }

    static void writeLog() {
        System.out.println("Writing log for " + USER.get());
    }
}
				
			

The output we get when running this code is:

				
					Processing request for David
Writing log for David
				
			

ScopedValue provides Java developers with a structured mechanism for sharing contextual information across method calls without polluting APIs with parameters that intermediate methods do not need.

Share:

Custom Gatherer

Creating a Custom Gatherer in Java

The gatherers allows us to define custom intermediate stream operations with their own state, processing logic, parallel-combination strategy, and finishing behavior. They are especially useful when standard stream operations are not expressive enough.

The CopyOnWriteArrayList Class

Working with CopyOnWriteArrayList in Java

The CopyOnWriteArrayList class is a thread-safe collection designed for cases in which reads are frequent and modifications are relatively rare. Its copy-on-write strategy makes iteration simple and safe, but writes come with an additional cost.

The Beauty of Code

Coding is Art! Developing Code That Works is Simple. Develop Code with Style is a Challenge!

Update cookies preferences