コード例 #1
0
  public PointUpdaterDaemon() {
    con = null;
    stm = null;
    //	rs               = null;
    //	affectedRow      = 0;
    recordCounter = 0;
    statCreate = false;
    statMonthly = false;
    statQuarterly = false;
    statGrandprize = false;
    workingDir = System.getProperty("user.dir");
    monthlyFile = PropertiesLoader.getProperty("POINT_MONTHLY_FILE");
    quarterlyFile = PropertiesLoader.getProperty("POINT_QUARTERLY_FILE");
    grandprizeFile = PropertiesLoader.getProperty("POINT_GRANDPRIZE_FILE");
    recSeparator = '|';
    escChar = '\'';
    headerLine = 1;

    // Establishing a Single DB Connection.
    // This Connection is usable across app life-cycle.
    try {
      db_object = new MysqlConnect();
      con = db_object.getConnection();
    } catch (ClassNotFoundException nfe) {
      nfe.printStackTrace();
    } catch (SQLException sqle) {
      sqle.printStackTrace();
    }
  }
コード例 #2
0
  @SuppressWarnings("unused")
  public static void main(String[] args) throws IOException, SQLException {
    // Evaluation Timer
    System.out.println("[MAIN PROCESS] Started: " + getCurrentTimeStamp());
    LogLoader.setInfo(
        PointUpdaterDaemon.class.getSimpleName(),
        "[MAIN PROCESS] Started: " + getCurrentTimeStamp());
    long startTime = System.currentTimeMillis();

    pointDaemon = new PointUpdaterDaemon();

    // Choose these options:

    // (A) Fresh start with ALL INSERT. Separated Tables.
    // 3 Separated Point Tables would be Created, then Inserted.

    // Creating Table must be DONE BEFORE running INSERTION Threads.
    pointDaemon.createTruncateSeparatedPointTables();

    // 1. With Single, Blocking Process (No Thread Programming)
    if (false) {
      pointDaemon.insertMonthlyPoint();
      pointDaemon.insertQuarterlyPoint();
      pointDaemon.insertGrandprizePoint();
    }
    // 2. With Concurrent, Multi-Thread Programming
    else if (true) {
      Runnable monthlyRunnable =
          new Runnable() {
            public void run() {
              System.out.println(
                  "[THREAD] ["
                      + getCurrentTimeStamp()
                      + "]"
                      + "Thread 1: Inserting Monthly Point Records..");
              LogLoader.setInfo(
                  PointUpdaterDaemon.class.getSimpleName(),
                  "[THREAD 1 START] [" + getCurrentTimeStamp() + "]");
              try {
                pointDaemon.insertMonthlyPoint();
              } catch (IOException | SQLException e) {
                e.printStackTrace();
              }
              System.out.println(
                  "[THREAD] [" + getCurrentTimeStamp() + "]" + "Thread 1: Finished.");
              LogLoader.setInfo(
                  PointUpdaterDaemon.class.getSimpleName(),
                  "[THREAD 2 STOP] [" + getCurrentTimeStamp() + "]");
            }
          };
      Runnable quarterlyRunnable =
          new Runnable() {
            public void run() {
              System.out.println(
                  "[THREAD] ["
                      + getCurrentTimeStamp()
                      + "]"
                      + "Thread 2: Inserting Quarterly Point Records..");
              LogLoader.setInfo(
                  PointUpdaterDaemon.class.getSimpleName(),
                  "[THREAD 2 START] [" + getCurrentTimeStamp() + "]");
              try {
                pointDaemon.insertQuarterlyPoint();
              } catch (IOException | SQLException e) {
                e.printStackTrace();
              }
              System.out.println(
                  "[THREAD] [" + getCurrentTimeStamp() + "]" + "Thread 2: Finished.");
              LogLoader.setInfo(
                  PointUpdaterDaemon.class.getSimpleName(),
                  "[THREAD 2 STOP] [" + getCurrentTimeStamp() + "]");
            }
          };
      Runnable grandprizeRunnable =
          new Runnable() {
            public void run() {
              System.out.println(
                  "["
                      + getCurrentTimeStamp()
                      + "]"
                      + "Thread 3: Inserting Grand Prize Point Records..");
              LogLoader.setInfo(
                  PointUpdaterDaemon.class.getSimpleName(),
                  "[THREAD 3 START] [" + getCurrentTimeStamp() + "]");
              try {
                pointDaemon.insertGrandprizePoint();
              } catch (IOException | SQLException e) {
                e.printStackTrace();
              }
              System.out.println("[" + getCurrentTimeStamp() + "]" + "Thread 3: Finished.");
              LogLoader.setInfo(
                  PointUpdaterDaemon.class.getSimpleName(),
                  "[THREAD 3 STOP] [" + getCurrentTimeStamp() + "]");
            }
          };

      Thread monthlyThread = new Thread(monthlyRunnable);
      Thread quarterlyThread = new Thread(quarterlyRunnable);
      Thread grandprizeThread = new Thread(grandprizeRunnable);

      // Setting Daemon Mode if Necessary

      // monthlyThread.setDaemon(true);
      // quarterlyThread.setDaemon(true);
      // grandprizeThread.setDaemon(true);

      monthlyThread.start();
      quarterlyThread.start();
      grandprizeThread.start();

      // Processing Time, If using No Thread Concept
      long endTime = System.currentTimeMillis();
      long duration = endTime - startTime;
      System.out.println("[MAIN PROCESS] Duration: " + duration + " ms.");
      LogLoader.setInfo(
          PointUpdaterDaemon.class.getSimpleName(),
          "[MAIN PROCESS] Finished: " + getCurrentTimeStamp() + "(" + duration + " ms).");
    }

    // (B) Fresh start with ONE INSERT, TWO UPDATES. One united point Table.
    // 1 Point Table would be Created, then Inserted once, Updated twice.
    /*
    pointDaemon.createTruncateUnitedPointTable();
    pointDaemon.insertMonthlyPoint();
    pointDaemon.updateQuarterlyPoint();
    pointDaemon.updateGrandprizePoint();
    */
    // (C) Current start with existing records
    /*
    pointDaemon.updateMonthlyPoint();
    pointDaemon.updateQuarterlyPoint();
    pointDaemon.updateGrandprizePoint();
    */

    // Final Result Report
    if (statCreate) System.out.println("[RESULT]: TABLES CREATED.");
    if (statMonthly) System.out.println("[RESULT]: MONTHLY POINTS INSERTED.");
    if (statQuarterly) System.out.println("[RESULT]: QUARTERLY POINTS INSERTED.");
    if (statGrandprize) System.out.println("[RESULT]: GRAND PRIZE POINTS INSERTED.");
  }