/*- package main import "fmt" func tasker (o, r chan int, d chan bool) { o <- 1; o <- 2 fmt.Println (<-r); d <- true } func add (o, r chan int) { r <- ((<-o) + (<-o)) } func main () { operand, result := make(chan int), make(chan int) done:= make(chan bool) go tasker (operand, result, done) go add (operand, result) <-done } */ import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; public class Sum { public static void main(String... args) throws InterruptedException { var operand = new LinkedBlockingQueue(); var result = new LinkedBlockingQueue(); var done = new LinkedBlockingQueue(); (new Thread(() -> tasker(operand, result, done))).start(); (new Thread(() -> add(operand, result))).start(); done.take(); } public static void tasker(BlockingQueue o, BlockingQueue r, BlockingQueue d) { o.offer(3); o.offer(2); try { System.out.println(r.take()); } catch (InterruptedException e) { throw new RuntimeException(e); } d.offer(true); } public static void add(BlockingQueue o, BlockingQueue r) { try { r.offer(Integer.valueOf(o.take()) + Integer.valueOf(o.take())); } catch (InterruptedException e) { throw new RuntimeException(e); } } }