2011-03-07 34 views
0

我的Java程序似乎在我使用Windows shell運行後掛起。我不知道如何解決這個錯誤:Java程序在Window shell中掛起

C:\quadrantRDBTemplate>java -cp iucbrf.jar;mysql-connector-java-5.0.jar edu.indi 
ana.iucbrf.examples.quadrantRDBTemplate.QuadrantTestClassRDB > 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) 

編輯: 這裏是我修改,以訪問MySQL的2個文件的源代碼的一部分,其他的都不變:

QuadrantSystemRDB.java

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()); 
    } 
} 

QuadrantTestClassRDB.java

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(); 
     } 
    } 
} 
+0

我們沒有足夠的代碼來幫助您解決此問題。我假設你使用這個[印第安納大學基於案例的推理框架](http://www.cs.indiana.edu/~sbogaert/CBR/),但IUCBRF不能下載,所以我不能嘗試它在我的機器上幫助你找出問題所在。 這似乎是你最好的選擇是聯繫作者,[史蒂文Bogaerts](http://www.cs.indiana.edu/cgi-bin/tomail.cgi?name=sbogaert),與您的問題。 – 2011-03-07 06:46:58

+0

這些代碼來自CVS ..我附上了我修改的部分。 – karikari 2011-03-07 06:55:31

+0

原代碼使用oracle數據庫。我修改它以使用MySQL。突然得到這個錯誤:( – karikari 2011-03-07 06:56:59

回答

0

看起來你有一個後臺線程崩潰(當讀取Base64數據時意外的文件結束),程序可能沒有處理這個,而是等待(無限期地)讓線程返回一些結果。

嘗試修復輸入數據,然後(如果它是您的程序)添加一些錯誤處理(即捕獲異常並通知程序沒有數據可讀)。

+0

這是否涉及到泛型? – karikari 2011-03-07 07:29:27

+2

@ karikari:不,看起來你的輸入是不完整的Base64,但在結束之前切斷。 – 2011-03-07 13:01:47