Java program hangs at Window shell
<p>My Java program seems to hang after I run it using Windows shell. I dont understand how to solve this error:</p>

<pre><code>C:\quadrantRDBTemplate&gt;java -cp iucbrf.jar;mysql-connector-java-5.0.jar edu.indi
ana.iucbrf.examples.quadrantRDBTemplate.QuadrantTestClassRDB &gt; log.txt
Exception in thread "Thread-3" java.lang.RuntimeException: java.lang.RuntimeExce
ption: java.io.EOFException
        at edu.indiana.util.Base64Tools.decode(Base64Tools.java:58)
        at edu.indiana.iucbrf.feature.featurespec.FeatureSpecRDB.setAllFeatureSp
ecShellsIntoCache(FeatureSpecRDB.java:238)
        at edu.indiana.iucbrf.feature.featurespec.FeatureSpecRDB.readFeatureSpec
RDBIntoCache(FeatureSpecRDB.java:201)
        at edu.indiana.iucbrf.feature.featurespec.FeatureSpecRDB.doThreadedOpera
tion(FeatureSpecRDB.java:189)
        at edu.indiana.util.multithreaded.DBLoaderThread.run(DBLoaderThread.java
:57)
        at java.lang.Thread.run(Unknown Source)
</code></pre>

<p>Edit:
Here is the 2 files source code part that I modified to access MySQL, others are the untouched:</p>

<p><strong>QuadrantSystemRDB.java</strong></p>

<pre><code>package edu.indiana.iucbrf.examples.quadrantRDBTemplate;

import edu.indiana.iucbrf.feature.FeatureKey;
import edu.indiana.iucbrf.maintenance.NullMaintenance;
import edu.indiana.iucbrf.retrieval.Retrieval;
import edu.indiana.iucbrf.retrieval.kNN;
import edu.indiana.iucbrf.adaptation.DistanceWeightedAdapter;
import edu.indiana.iucbrf.performancemonitor.PerformanceMonitor;
import edu.indiana.iucbrf.problem.ProblemGenerator;
import edu.indiana.iucbrf.casepackage.CaseGenerator;
import edu.indiana.iucbrf.casebase.FlatCaseBase;
import edu.indiana.iucbrf.cbrsystem.CBRSystem;
import edu.indiana.util.distribution.UniformDistribution;
import java.util.HashMap;
import java.sql.Driver;

import java.sql.DriverManager;  
import java.sql.Connection;     
import java.sql.SQLException;   
import java.util.Map;  

import edu.indiana.iucbrf.casebase.RDBCaseBase;
import edu.indiana.iucbrf.feature.featurespec.FeatureSpecCollection;
import edu.indiana.iucbrf.feature.FeatureCollection;
import edu.indiana.iucbrf.feature.featurespec.FeatureSpecRDBInfo;
import edu.indiana.util.db.JDBCDriverInfo;
import edu.indiana.iucbrf.casebase.RDBCaseBaseInfo;
import edu.indiana.iucbrf.domain.DBInfo;



public class QuadrantSystemRDB
    extends CBRSystem {

    ///////////////////////////////////////////////////////////////////////////
    // Database configuration
    public static final String USERNAME;
    public static final String PASSWORD;
    //public static final String HOST_NAME;
    //public static final String SERVICE_NAME;

    /* Set the above variables appropriately for your database configuration.  Additional
     * code modifications may also be necessary depending on your configuration.
     */
    static {
        //if (true)
        //    throw new UnsupportedOperationException("\n\n*************** NOTICE ***************\nThis exception is expected!  You must set a few constants in QuadrantSystemRDB, according to your database configuration, and then comment out this exception.");
         USERNAME = "root";
         PASSWORD = "123456";
        // HOST_NAME = "localhost";
        // SERVICE_NAME = "";
    }
    ///////////////////////////////////////////////////////////////////////////

    /** The number of cases to be in the case base.  Of course, performance of
     *  the system depends on how many cases are available.
     */
    private static final int NUM_CASES = 5;

    /** The keys to the two problem features. */
    private FeatureKey xKey;
    private FeatureKey yKey;
    DBInfo dbInfo;
    FeatureSpecRDBInfo problemSpecInfo;
    FeatureSpecRDBInfo solutionSpecInfo;
    RDBCaseBaseInfo rdbCasebaseInfo;

    /** Creates a new instance of QuadrantSystem */
    public QuadrantSystemRDB() {

        //Defines the required info classes
        //setupInfo();
        try {
            setupInfo();
            }
            catch (java.sql.SQLException e) {
             // you may want to do something useful here
             // maybe even throw new RuntimException();
            }


        // Define the domain, which describes the type of problems the system will solve.
        setupDomain();

        // Create the case base and add cases to it.
        setupCaseBase();

        // Do no maintenance for this system
        setMaintenance(new NullMaintenance());

        // Retrieval will be 5-nearest neighbor
        Retrieval retrieval = new kNN(getDomain().getProblemDifferentiator(), 5);
        setRetrieval(retrieval);

        // The adaptation technique is a distance-weighted majority vote.
        setAdaptation(new DistanceWeightedAdapter("edu.indiana.iucbrf.adaptation.WeightedMajorityAdapter"));

        // Track the system performance with the performance monitor
        setPerformanceMonitor(new PerformanceMonitor());
    }

    private void setupInfo() throws SQLException
    {
        Driver driver = new com.mysql.jdbc.Driver();

        String url = "jdbc:mysql://localhost:3306/hpdata";
        String username = USERNAME;
        String password = PASSWORD;
        String problemFeatureSpecTableName = "ProblemFeatureSpec";
        String solutionFeatureSpectTableName = "SolutionFeatureSpec";
        String classTableName = "Class";
        String extraDataTableName = "ExtraData";
        String casebaseTablename = "CaseBase";
        String problemTableName = "Problem";
        String solutionTableName = "Solution";
        String inactiveContextsTableName = "InactiveContext";
        String constantsTableName = "Constants";
        dbInfo = new DBInfo(new JDBCDriverInfo(driver, url, username, password),constantsTableName);
        problemSpecInfo = new FeatureSpecRDBInfo(problemFeatureSpecTableName, classTableName, extraDataTableName);
        solutionSpecInfo = new FeatureSpecRDBInfo(solutionFeatureSpectTableName, classTableName, extraDataTableName);
        rdbCasebaseInfo = new RDBCaseBaseInfo(casebaseTablename, solutionTableName, problemTableName, inactiveContextsTableName);
    }


    // Define the domain, which describes the type of problems the system will solve.
    private void setupDomain() {
        QuadrantDomainRDB domain = new QuadrantDomainRDB(dbInfo, problemSpecInfo, solutionSpecInfo);

        /* Add the two problem features: x and y.  The textual description,
         * type, and similarity weight are specified.  The return values are keys
         * that will be referred to in additional setup steps.
         */

        long start, end, totalTime;
        start = System.currentTimeMillis();
        xKey = domain.addProblemFeature("x", "edu.indiana.iucbrf.feature.DoubleFeature", 1, true);
        end = System.currentTimeMillis();
        totalTime = end - start;
        System.out.println("Total Time to add a featurespec: " + totalTime + " in millisec");


        FeatureSpecCollection fsc = domain.getFeatureSpecCollection(FeatureCollection.PROBLEM_FEATURE_COLLECTION);
        start = System.currentTimeMillis();
        fsc.getFeatureSpec(xKey);
        end = System.currentTimeMillis();
        totalTime = end - start;
        System.out.println("Total Time to get a featurespec: " + totalTime + " in millisec");

        yKey = domain.addProblemFeature("y", "edu.indiana.iucbrf.feature.DoubleFeature", 1, true);

        /* Add the solution feature: quadrant.  A key is assigned, but it is not
         * needed at this time.
         */

        domain.addSolutionFeature("Quadrant", "edu.indiana.iucbrf.feature.IntegerFeature");

        /* The reference solution for this domain requires the xKey and yKey.  See
         introductory paper for details on reference methods. */

        domain.prepareReferenceSolution(xKey, yKey);

        setDomain(domain);

    }

    /** The case base must be populated.  For this example, random generation is
     *  possible and sufficient.
     */
    private void setupCaseBase() {

        // The case generator can be built from the problem generator.
        CaseGenerator cg = new CaseGenerator(constructProblemGenerator(), getDomain());

        /** Construct the case base, with a simple flat structure.  For this
         * constructor, the case generator and the desired number of initial cases
         * can be passed.
         */
        long start;
        long end;
        long totalTime;
        start = System.currentTimeMillis();
        setCB(new RDBCaseBase(getDomain(), rdbCasebaseInfo, cg, NUM_CASES));
        end = System.currentTimeMillis();
        totalTime = end - start;
        System.out.println("Total Time to setup casebase with " + NUM_CASES + " : " + totalTime + " in millisec");
    }

    /**  A problem generator requires specification of arguments to send to
     * feature constructors.  Here, random distributions are used.
     */


    public ProblemGenerator constructProblemGenerator() {
        HashMap argMap = new HashMap(2);
        argMap.put(xKey, new UniformDistribution(-1, 1));
        argMap.put(yKey, new UniformDistribution(-1, 1));

        return new ProblemGenerator(argMap, getDomain());
    }
}
</code></pre>

<p><strong>QuadrantTestClassRDB.java</strong></p>

<pre><code>package edu.indiana.iucbrf.examples.quadrantRDBTemplate;

import edu.indiana.iucbrf.problem.Problem;
import java.sql.Driver;
import java.io.IOException;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;

/**
 * This class contains a simple main method that constructs a QuadrantSystemRDB
 * and tests it on a single problem.  This demonstrates basic database functionality.
 * In order to run this program, you will need to configure your database
 * (edu/creation_script.sql may be helpful in this task) and perhaps
 * modify the settings here accordingly.  You will also need to set some parameters as
 * discussed in QuadrantSystemRDB.
 *
 * @author  Steven Bogaerts
 */
public class QuadrantTestClassRDB {

    /** Constructs the system, and tests it on a single problem. */
    public static void main(String[] args) {
        System.out.println("Hello World! ...... ");
        flush();

        long start, end, totalTime;

        // Construct the system.
        start = System.currentTimeMillis();

        QuadrantSystemRDB sys = new QuadrantSystemRDB();
        end = System.currentTimeMillis();
        totalTime = end - start;
        System.out.println("Total Time to construct system: " + totalTime + " in millisec");

        // Set the system to show a GUI of its status.
        sys.setGUIMode(true);

        /* Generate a problem to test the system on.  This problem generator is
        defined in the QuadrantSystem class. */
        start = System.currentTimeMillis();

        Problem p = sys.constructProblemGenerator().generateProblem();
        end = System.currentTimeMillis();
        totalTime = end - start;
        System.out.println("Total Time to generate a problem: " + totalTime + " in millisec");

        // Solve the problem.  The GUI will show what happens.
        start = System.currentTimeMillis();
        sys.solve(p);
        sys.close();
        end = System.currentTimeMillis();
        totalTime = end - start;
        System.out.println("Total Time to solve a problem: " + totalTime + " in millisec");
    }

    private static void flush() {
        String url = "jdbc:mysql://localhost:3306/hpdata";
        Connection con;
        Statement stmt;
        String query1 = "Delete from casebase";
        String query2 = "Delete from problem";
        String query3 = "Delete from solution";
        String query4 = "Delete from problemfeaturespec";
        String query5 = "Delete from solutionfeaturespec";
        String query6 = "Delete from inactivecontext";
        String query7 = "Delete from class";
        String query8 = "Delete from extradata";

        try {
            DriverManager.registerDriver(new com.mysql.jdbc.Driver());
           // DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
        } catch (Exception e) {
            System.out.println("Class Not Found Exception:");
            System.out.println(e.getMessage());
        }




        try {
            con = DriverManager.getConnection(url, QuadrantSystemRDB.USERNAME, QuadrantSystemRDB.PASSWORD);
            stmt = con.createStatement();
            System.out.println("Deleting Tables from Database...");
            System.out.println("casebase...");
            stmt.executeUpdate(query1);
            System.out.println("deleted\n");
            System.out.println("problem...");
            stmt.executeUpdate(query2);
            System.out.println("deleted\n");
            System.out.println("solution...");
            stmt.executeUpdate(query3);
            System.out.println("deleted\n");
            System.out.println("problemfeaturespec...");
            stmt.executeUpdate(query4);
            System.out.println("deleted\n");
            System.out.println("solutionfeaturespec...");
            stmt.executeUpdate(query5);
            System.out.println("deleted\n");
            System.out.println("inactivecontext...");
            stmt.executeUpdate(query6);
            System.out.println("deleted\n");
            System.out.println("class...");
            stmt.executeUpdate(query7);
            System.out.println("deleted\n");
            System.out.println("extradata...");
            stmt.executeUpdate(query8);
            System.out.println("deleted\n");
            stmt.close();
            con.close();
        } catch (Exception e) {
            System.out.println("SQLException:" + e.getMessage());
            e.printStackTrace();
        }
    }
}
</code></pre>
