This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private long numberOfPeopleNamedJohn(List<Person> people) { | |
List<Person> localPeople = new ArrayList<>(); | |
localPeople.addAll(people); | |
return localPeople.stream().filter(person -> person.getFirstName().equals("John")).count(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lombok.Builder; | |
@Builder | |
public class Person { | |
private final String firstName; | |
private final String lastName; | |
private final String middleName; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lombok.Builder; | |
@Builder | |
public final class Student extends Person { | |
private final String rollNumber; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<>(); |