英文:
TimerTask Scheduler Not working after static reference to other class object
问题
以下是已翻译的内容:
IbftUtil.java:
static {
try {
/******************** 读取属性文件.. **********************/
LOGGER.println(LOG + " 加载属性文件.. ");
InputStream inputStream = new FileInputStream(new File(FMS_PROPERTY_FILE));
fmsProperties = new Properties();
fmsProperties.load(inputStream);
LOGGER.println(LOG + " 属性文件加载成功 ");
inputStream.close();
LOGGER.println(LOG + " 读取属性值.. ");
// 定时器属性..
delayTime = Long.parseLong(fmsProperties.getProperty(IBFT_DELAY_TIME));
executionTime = Long.parseLong(fmsProperties.getProperty(IBFT_EXECUTION_TIME));
LOGGER.println(LOG + " IBFT 延迟与执行时间 = " + getDelayTime() + "," + getExecutionTime());
// 密钥库和证书..
ibftReceiverCertificate = fmsProperties.getProperty(IBFT_RECEIVER_CERTIFICATE);
ibftSenderKeyStore = fmsProperties.getProperty(IBFT_SENDER_KEY_STORE);
ibftKeyStoreAlias = fmsProperties.getProperty(IBFT_KEY_STORE_ALIAS);
// 密钥库凭证..
ibftKeyStoreKey = fmsProperties.getProperty(IBFT_KEY_STORE_KEY);
ibftKeyStorePath = fmsProperties.getProperty(IBFT_KEY_STORE_PASS);
// 复制文件路径..
ibftPaymentFiles = fmsProperties.getProperty(IBFT_PAYMENT_FILES);
LOGGER.println(LOG + " 属性值读取成功!.. ");
/******************** 数据库连接.. ********************/
LOGGER.println(LOG + " 连接数据库 ");
connection = DatabaseConnection.getDatabaseConnection().getConnection(FMS_POST_SOURCE);
connection.setAutoCommit(false);
LOGGER.println(LOG + " FMS 数据库已连接.. ");
} catch (Exception e) {
LOGGER.println(LOG + " 单例块中出现异常 " + e);
}
}
TimerTask.java:
class IbftFileTimerTask extends TimerTask implements IConstants {
// 变量用于保存从查询返回的值..
private String fundBankId = EMPTY_STRING;
private String fundId = EMPTY_STRING;
private String fundBankAccountNo = EMPTY_STRING;
private String productType = EMPTY_STRING;
private String ibftDirectoryName = EMPTY_STRING;
private String bankShortName = EMPTY_STRING;
private String ibftCallingView = EMPTY_STRING;
private String ibftFileName = EMPTY_STRING;
private String amcShortName = EMPTY_STRING;
private String cnicOrNtn = EMPTY_STRING;
private String paymentRecordId = EMPTY_STRING;
private String ibftDirectoryPath = EMPTY_STRING;
// 用于硬编码产品类型的变量..
private String fileProductType = EMPTY_STRING;
// 用于保存已处理付款记录的ArrayList..
private ArrayList<String> paymentRecordIdList = null;
// 用于追加到文件名中的文件序列计数器..
private int fileSequence = 0;
// Utility Class 的类对象..
private static IbftUtil util = new IbftUtil();
/**
* *******************************************************************************
* EPM 文件加密 - 调度程序
* *******************************************************************************
*/
public void run() {
LOGGER.println(LOG + " 时间 = " + util.getSystemDate());
LOGGER.println(LOG + " IBFT 支付文件定时器启动..");
try {
executor();
} catch (Exception e) {
LOGGER.println(LOG + " 异常=" + e.getMessage());
}
LOGGER.println(LOG + " IBFT 支付文件定时器结束..");
}
@SuppressWarnings("static-access")
public static void main(String[] args) throws SQLException {
LOGGER.println(LOG + " ---- IBFT 定时器任务 ---- ");
// 实例化 Timer 对象
Timer time = new Timer();
// 类对象
IbftUtil util = new IbftUtil();
// 实例化 EPMTimerTask 类
IbftFileTimerTask ibft = new IbftFileTimerTask();
// 每 2 分钟创建重复执行的任务
time.schedule(ibft, util.delayTime, util.executionTime);
}
}
英文:
I have a TimeTask class with reference to other class. Now, when I am creating the static reference to another class; its only executing the static block of that class and the main method of the timer task class is not executing;
I might be doing some sort of referencing mistake as in the IbftUtil.java class I tried to make things singleton by introducing that static block.
please help.
IbftUtil.java
static {
try {
/******************** Read Properties file.. ***************/
LOGGER.println( LOG + " Loading properties file.." );
InputStream inputStream = new FileInputStream( new File( FMS_PROPERTY_FILE ) );
fmsProperties = new Properties();
fmsProperties.load( inputStream );
LOGGER.println( LOG + " Properties Loaded Successfully" );
inputStream.close();
LOGGER.println( LOG + " Reading properties values.. " );
// Timer attributes..
delayTime = Long.parseLong( fmsProperties.getProperty ( IBFT_DELAY_TIME ) );
executionTime = Long.parseLong( fmsProperties.getProperty ( IBFT_EXECUTION_TIME ) );
LOGGER.println( LOG + " IBFT DELAY & EXECUTION TIME = " + getDelayTime() + "," + getExecutionTime());
// Key-store and certificate ..
ibftReceiverCertificate = fmsProperties.getProperty( IBFT_RECEIVER_CERTIFICATE );
ibftSenderKeyStore = fmsProperties.getProperty( IBFT_SENDER_KEY_STORE );
ibftKeyStoreAlias = fmsProperties.getProperty( IBFT_KEY_STORE_ALIAS );
// Key store credentials..
ibftKeyStoreKey = fmsProperties.getProperty( IBFT_KEY_STORE_KEY );
ibftKeyStorePath = fmsProperties.getProperty( IBFT_KEY_STORE_PASS );
// Copy file path..
ibftPaymentFiles = fmsProperties.getProperty( IBFT_PAYMENT_FILES );
LOGGER.println( LOG + " Properties values read successfully!.. " );
/******************** Database Connection.. ********************/
LOGGER.println( LOG + " Connecting to Database" );
connection = DatabaseConnection.getDatabaseConnection().getConnection( FMS_POST_SOURCE );
connection.setAutoCommit( false );
LOGGER.println( LOG + " FMS Database Connected.." );
} catch ( Exception e ) {
LOGGER.println( LOG + " Exception in Singleton block " + e );
}
}
TimerTask.java
class IbftFileTimerTask extends TimerTask implements IConstants {
// Variables to hold to values returned from queries..
private String fundBankId = EMPTY_STRING;
private String fundId = EMPTY_STRING;
private String fundBankAccountNo = EMPTY_STRING;
private String productType = EMPTY_STRING;
private String ibftDirectoryName = EMPTY_STRING;
private String bankShortName = EMPTY_STRING;
private String ibftCallingView = EMPTY_STRING;
private String ibftFileName = EMPTY_STRING;
private String amcShortName = EMPTY_STRING;
private String cnicOrNtn = EMPTY_STRING;
private String paymentRecordId = EMPTY_STRING;
private String ibftDirectoryPath = EMPTY_STRING;
// Variable for Hard-coded product type..
private String fileProductType = EMPTY_STRING;
// ArrayList for holding paymentRecords Processed..
private ArrayList<String> paymentRecordIdList = null;
// File Sequence counter for appending in file name..
private int fileSequence = 0;
// Class Object for Utility Class..
private static IbftUtil util = new IbftUtil();
/**
* *******************************************************************************
* EPM FILE ENCRYPTION - SCHEDULER
* *******************************************************************************
*/
public void run() {
LOGGER.println( LOG + " Time = " + util.getSystemDate() );
LOGGER.println( LOG + " IBFT Payment Files timer starts.." );
try {
executor();
}
catch (Exception e) {
LOGGER.println( LOG + " Exception=" + e.getMessage() );
}
LOGGER.println( LOG + " IBFT Payment Files timer Ends.." );
}
@SuppressWarnings("static-access")
public static void main ( String[] args ) throws SQLException {
LOGGER.println( LOG + " ---- IBFT TIMER TASK ---- " );
// Instantiate Timer Object
Timer time = new Timer();
// Class object
IbftUtil util = new IbftUtil();
// Instantiate EPMTimerTask class
IbftFileTimerTask ibft = new IbftFileTimerTask();
// Create Repetitively task for every 2 minutes
time.schedule( ibft, util.delayTime, util.executionTime );
}
专注分享java语言的经验与见解,让所有开发者获益!
评论