runobject.java

来自「用于求解TSP(Traveling salesman problem」· Java 代码 · 共 57 行

JAVA
57
字号
/**
 * Description: For a RunObject, it has some input pins, some control pins
 * (optional), and some output pins.
 *
 * @ Author        Create/Modi     Note
 * Xiaofeng Xie    May 22, 2000    xiaofengxie@tsinghua.org.cn
 *
 * @version 1.0
 * @Since MAOS1.0
 */
package Global.system;

import java.util.*;

import Global.define.*;

abstract public class RunObject extends ThreadObject {

  public RunObject() {}

/**
 * Run Object.
 */
  public void run() {
    synchronized(this){
      long time = System.currentTimeMillis();
      printTitle();
      try {
        pureRun();
        time = System.currentTimeMillis()-time;
        System.out.println("@ "+this.getKey()+"->Total "+((double)time/1000.0)+" second costed.");
      } catch(Exception e) {
        stop();
        System.out.println(e.getMessage());
      }
    };
  }

  public void pureRun() throws Exception {
    run_flag = FLAG_RUNNING;
    runObject();
    run_flag = FLAG_STOP;
  }

/**
 * Run Object.
 */
  abstract protected void runObject() throws Exception;

  protected void printTitle() {
    System.out.println("*********************************************");
    System.out.println("* [ "+getKey()+" ]");
    System.out.println("* "+Calendar.getInstance().getTime().toString());
    System.out.println("*********************************************");
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?