Skip to content

Instantly share code, notes, and snippets.

View sbvalijon's full-sized avatar

Valijon sbvalijon

  • Uzbekistan, Tashkent
View GitHub Profile
@sbvalijon
sbvalijon / Solution.java
Last active August 5, 2021 01:58
Checks if all packages can be installed and prints the installation order
package uz.valijon;
import static uz.valijon.PackageState.CHECKED_CANNOT_BE_INSTALLED;
import static uz.valijon.PackageState.CHECKED_CAN_BE_INSTALLED;
import static uz.valijon.PackageState.UNCHECKED;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@sbvalijon
sbvalijon / Bar.java
Last active January 18, 2019 13:14
ThreadLocal usage examaple
/**
* It is instantiated only once.
* However can be initialized one or more times per thread.
* The code prints something like this on console:
* field threadLocal has been instantiated!
* Thread with id = 10
* Thread with id = 11
* Thread with id = 12
* */
public class Bar {
public class ThreadLocalExample {
public static class MyRunnable implements Runnable {
private ThreadLocal<Integer> threadLocal =
new ThreadLocal<Integer>();
@Override
public void run() {
threadLocal.set( (int) (Math.random() * 100D) );
try {