package net.blackshard.clarity.scribe;

import net.blackshard.clarity.tome.Library;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;

/**
 * @author Matthew R. Trower
 * class App
 * 
 * Main driver class for Scribe.  Loads up scribblets and runs them, asynchronously.
 */
public class App {
    private static final Logger log = LogManager.getLogger(App.class);
    private static List<Runnable> scribblets;

    static {
        log.info("Driver: initializing...");

        Library.open();

        scribblets = new ArrayList();
        scribblets.add(new CPUScribblet());
        scribblets.add(new MemScribblet());

        log.info("Driver: initialization complete");
    }

    public static void main( String[] args ) {
        log.info("Driver: launching scribblets...");

        for (Runnable r: scribblets) {
            Thread t = new Thread(r);
            threads.add(t);
            t.start();
        }

        log.info("Driver: all scribblets launched");

        try {
            for (Thread t: threads)
                t.join();
        } catch (InterruptedException ie) { }

        log.info("Driver: cleaning up");

        Library.close();
    }
}

@@ -167,59 +167,8 @@
 r;%0A%0A
-import java.util.List;%0Aimport java.util.ArrayList;%0A
 impo
@@ -460,19 +460,18 @@
  static 
-Lis
+Se
 t%3CRunnab
@@ -490,19 +490,80 @@
 ts;%0A
-%0A    static
+    private static Set%3CThread%3E threads;%0A%0A    private static void setUp()
  %7B%0A 
@@ -628,24 +628,57 @@
 ry.open();%0A%0A
+        threads = new HashSet();%0A
         scri
@@ -694,16 +694,14 @@
 new 
-ArrayLis
+HashSe
 t();
@@ -855,21 +855,22 @@
 %7D%0A%0A    p
-ublic
+rivate
  static 
@@ -878,28 +878,25 @@
 oid 
-main( String%5B%5D args 
+launchScribblets(
 ) %7B%0A
@@ -1137,24 +1137,73 @@
 launched%22);%0A
+    %7D%0A%0A    private static void waitForThreads() %7B
 %0A        try
@@ -1313,16 +1313,59 @@
 ie) %7B %7D%0A
+    %7D%0A%0A    private static void tearDown() %7B
 %0A       
@@ -1429,11 +1429,158 @@
 );%0A    %7D
+%0A%0A    public static void main( String%5B%5D args ) %7B%0A        setUp();%0A%0A        launchScribblets();%0A        waitForThreads();%0A%0A        tearDown();%0A    %7D
 %0A%7D%0A

Refactor driver class