package edu.rice.comp322; import edu.rice.hj.api.HjFuture; import static edu.rice.hj.Module0.launchHabaneroApp; import static edu.rice.hj.Module1.future; /** * Solution to Worksheet 5. * * @author Shams Imam */ public final class Worksheet5 { /** * Disallow instance creation of utility class. */ private Worksheet5() { super(); } /** * The main method. * * @param args an array of {@link String} objects. */ public static void main(final String[] args) { launchHabaneroApp(() -> { final HjFuture A = future(() -> { return process("A"); }); final HjFuture B = future(() -> { A.get(); return process("B"); }); final HjFuture C = future(() -> { A.get(); return process("C"); }); final HjFuture D = future(() -> { B.get(); C.get(); return process("D"); }); final HjFuture E = future(() -> { C.get(); return process("E"); }); final HjFuture F = future(() -> { D.get(); E.get(); return process("F"); }); F.get(); }); } private static Void process(String a) { try { // random sleep to influence scheduling outputs Thread.sleep((long)(Math.random() * 2_000)); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(a); return null; } }