import java.io.*; import java.util.Scanner; import java.util.concurrent.*; import java.util.concurrent.locks.*; class Frekvens { int ant_prosesser; String[] data; String flest = "??"; int flestAntall = 0; Frekvens(String[] initData, int nPros) { data = initData; ant_prosesser = nPros; } String hentFlest() { return flest; } int hentAntall() { return flestAntall; } CountDownLatch barriere; Lock laas = new ReentrantLock(); class Leting implements Runnable { int nr, fra, til; Leting(int nr, int fra, int til) { this.nr = nr; this.fra = fra; this.til = til; } public void run() { System.out.println("Leteprosess nr " + nr + " leter i intervallet " + fra + "-" + til + "..."); String denne = data[fra]; int denneAntall = 1; String max = denne; int maxAntall = denneAntall; for (int i = fra+1; i <= til; i++) { if (data[i-1].equals(data[i])) { denneAntall++; } else { if (denneAntall > maxAntall) { max = denne; maxAntall = denneAntall; } denne = data[i]; denneAntall = 1; } } if (denneAntall > maxAntall) { max = denne; maxAntall = denneAntall; } try { laas.lock(); if (maxAntall > flestAntall) { flest = max; flestAntall = maxAntall; } } finally { laas.unlock(); } System.out.println("Leteprosess nr " + nr + " er ferdig."); barriere.countDown(); } } void finnFlest() { final int ant_per_prosess = (data.length-1)/ant_prosesser + 1; barriere = new CountDownLatch(ant_prosesser); try { int pNr = 0; int fra = 0; while (fra < data.length) { pNr++; int til = Math.min(fra+ant_per_prosess-1, data.length-1); while (til