Skip to content

Instantly share code, notes, and snippets.

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class ListOfMapToMap {
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class MergeTwoMaps {
public static void main(String[] args) {
Map<String, Long> map = new HashMap<>();
import java.util.concurrent.locks.ReentrantLock;
public class ReentrantLockInterruptiblyDemo {
private static ReentrantLock reentrantLock = new ReentrantLock();
public static void main(String[] args) throws InterruptedException {
ReentrantLockInterruptiblyDemo reentrantLockDemo = new ReentrantLockInterruptiblyDemo();
import java.util.concurrent.locks.ReentrantLock;
public class ReentrantLockFairnessDemo {
private static ReentrantLock reentrantLock = new ReentrantLock(true);
public static void main(String[] args) throws InterruptedException {
ReentrantLockFairnessDemo reentrantLockDemo = new ReentrantLockFairnessDemo();
import java.util.concurrent.locks.ReentrantLock;
public class ReentrantLockDemo {
private static ReentrantLock reentrantLock = new ReentrantLock();
public static void main(String[] args) throws InterruptedException {
ReentrantLockDemo reentrantLockDemo = new ReentrantLockDemo();
import java.util.concurrent.CountDownLatch;
public class CountDownLatchDemo {
private static final CountDownLatch COUNT_DOWN_LATCH = new CountDownLatch(5);
public static void main(String[] args) {
Thread run1 = new Thread(() -> {
System.out.println("Doing some work..");
import lombok.Builder;
public final class Student extends Person {
private final String rollNumber;
@Builder(builderMethodName = "studentBuilder")
public Student(final String firstName, final String lastName, final String middleName, final String rollNumber) {
super(firstName, lastName, middleName);
this.rollNumber = rollNumber;
import lombok.Builder;
@Builder
public final class Student extends Person {
private final String rollNumber;
}
import lombok.Builder;
@Builder
public class Person {
private final String firstName;
private final String lastName;
private final String middleName;
}
public class ThreadConfinementUsingThreadLocal {
public static void main(String[] args) {
ThreadLocal<String> stringHolder = new ThreadLocal<>();
Runnable runnable1 = () -> {
stringHolder.set("Thread in runnable1");
try {
Thread.sleep(5000);
System.out.println(stringHolder.get());