Skip to content

Instantly share code, notes, and snippets.

//id to detect which object was chosen to remain
case class TC(id: Long, value: String) {
override def equals(obj: Any): Boolean = obj match {
case tc: TC => value == tc.value
case _ => false
}
}
package popatsap.blog.kafkaexample;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
package com.example.demo;
import java.util.concurrent.CountDownLatch;
public class CountDownLatchExample {
private static final CountDownLatch START = new CountDownLatch(5);
public static void main(String[] args) throws InterruptedException {
System.out.println("Waiting 5 cars appearing to the start line");
package com.example.demo;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
public class CyclingBarrierExample {
private static final CyclicBarrier BARRIER = new CyclicBarrier(3, new FerryBoat());
public static void main(String[] args) throws InterruptedException {
package com.example.demo;
import java.util.concurrent.Semaphore;
public class SemaphoreExample {
private static final Semaphore PARKING = new Semaphore(3);
public static void main(String[] args) throws InterruptedException {
for (int i = 1; i <= 9; i++) {
@Normal
Normal / RxScalaBasedApproach.scala
Created December 27, 2017 21:36
RxScala example
import java.util.concurrent.{Executors, TimeUnit}
import rx.lang.scala.Observable
import scala.concurrent.duration._
//import scala.concurrent.ExecutionContext.Implicits.global
import rx.lang.scala.schedulers.{ComputationScheduler, ExecutionContextScheduler}
import scala.concurrent.{ExecutionContext, Future}
@Normal
Normal / RxScalaBasedApproach.scala
Created December 27, 2017 22:41
RxScala multithreaded
import java.util.concurrent.{Executors, TimeUnit}
import rx.lang.scala.Observable
import scala.concurrent.duration._
//import scala.concurrent.ExecutionContext.Implicits.global
import rx.lang.scala.schedulers.{ComputationScheduler, ExecutionContextScheduler}
import scala.concurrent.{ExecutionContext, Future}