package org.parser.marpa;

import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

/**
 * Test Application
 */
public class AppParse  {
	
	/**
	 * @param args arguments, unused
	 */
	public static void main(String[] args)  {
		AppLogger eslifLogger1 = new AppLogger();
		AppLogger eslifLogger2 = new AppLogger();
		AppLogger eslifLogger = eslifLogger2;
		int       nbthread = 5;
		int       ithread;
		ArrayList<Thread> threadlist = new ArrayList<Thread>();
		int       nbalive;

		/*
		eslifLogger.info(" ATTACH ME");
		try {
			TimeUnit.SECONDS.sleep(10);
		} catch (InterruptedException e) {
			System.err.println(e);
		}
		*/
		
		eslifLogger.info("Running over " + nbthread + " threads, using two loggers");
		
		for (ithread = 0; ithread < nbthread; ithread++) {
			eslifLogger = (eslifLogger == eslifLogger2) ? eslifLogger1 : eslifLogger2;
			eslifLogger.info("Starting thread No " + ithread + " with logger " + eslifLogger);
			Thread t = new Thread(new AppThread(eslifLogger));
			t.start();
			threadlist.add(t);
		}
		
		nbalive = nbthread;
		while (nbalive > 0) {
			nbalive = 0;
			for (int i = 0; i < threadlist.size(); i++) {
				Thread t = threadlist.get(i);
				if (t != null) {
					if (t.isAlive()) {
						eslifLogger.info("Thread No " + i + " is still alive");
						nbalive++;
					} else {
						threadlist.set(i, null);
					}
				}
			}
			if (nbalive > 0) {
				eslifLogger.info(nbalive + " threads alive - sleeping one second");
				try {
					TimeUnit.SECONDS.sleep(1);
				} catch (InterruptedException e) {
					System.err.println(e);
				}
			} else {
				eslifLogger.info("All " + threadlist.size() + " threads finished");
			}
		}
	}
}

@@ -384,9 +384,9 @@
 d = 
-5
+1
 ;%0A%09%09
@@ -1668,13 +1668,82 @@
 %09%09%7D%0A%09%09%7D%0A
+%09%09%0A%09%09// Import/export test%0A%09%09new AppImportExport(eslifLogger).run();%0A
 %09%7D%0A%7D%0A

call AppImportExport t+ [ci skip]