CompletableFuture
package
com.studyskymate.dinesh.corejava.java8;
import java.util.Arrays;
import java.util.List;
import
java.util.concurrent.CompletableFuture;
public class CompletableFutureEx {
public static void main(String[] args) {
List<Integer> list = Arrays.asList(5);
list.stream().map(
num -> CompletableFuture
.supplyAsync(() ->getNumber(num)))
.map(CompletableFuture -> CompletableFuture
.thenApply(n -> n * n)).map(t -> t.join())
.forEach(s -> System.out.println(s));
}
private static int getNumber(int a) {
return a * a;
}
}
Transactions and Isolation Level
Isolation level in a transactional method
@Autowired private TestDAO testDAO; @Transactional(isolation=Isolation.READ_COMMITTED) public void someTransactionalMethod(User user) { // Interact with testDAO }
dirty reads | non-repeatable reads | phantom reads | |
READ_UNCOMMITTED | yes | yes | yes |
READ_COMMITTED | no | yes | yes |
REPEATABLE_READ | no | no | yes |
SERIALIZABLE | no | no | no |
Example: Transaction A reads a range of records. Meanwhile, Transaction B inserts a new record in the same range that Transaction A initially fetched and commits.
Later Transaction A reads the same range again and will also get the record that Transaction B just inserted.This is a phantom read: a transaction fetched a range of records multiple times from the database and obtained different result sets (containing phantom records).
Microservices Design Pattern
a. Decompose by Business Capability
b. Decompose by Subdomain
c. Strangler Pattern
2. Integration Patterns
a. API Gateway Pattern
b. Aggregator Pattern
c. Client-Side UI Composition Pattern
3. Database Patterns
a. Database per Service
b. Shared Database per Service
c. Command Query Responsibility Segregation (CQRS)
d. Saga Pattern credit limit
4. Observability Patterns
a. Log Aggregation
b. Performance Metrics
c. Distributed Tracing
d. Health Check
5.Cross-Cutting Concern Patterns
a. External Configuration
b. Service Discovery Pattern
c. Circuit Breaker Pattern
d. Blue-Green Deployment Pattern
How to avoid Diamond Problem With Default Methods in Java 8
package
com.studyskymate.dinesh.corejava.java8;
public interface Poet {
default void write() {
System.out.println("Poet's default method");
}
static void write3() {
System.out.println("poet Writer static default method");
}
}
package
com.studyskymate.dinesh.corejava.java8;
public interface Writer {
default void write() {
System.out.println("Writer default method");
}
default void write2() {
System.out.println("Writer default method22");
}
static void write3() {
System.out.println(" write Writer static default method");
}
}
package
com.studyskymate.dinesh.corejava.java8;
public class Multitalented implements Poet, Writer {
public static void main(String[] args) {
Multitalented m = new Multitalented();
m.write();
}
//Need to override the ambiguous method otherwise there will be
compile time error
@Override
public void write() {
Writer.super.write();
System.out.println("In Multitalented class");
}
}
No comments:
Post a Comment