计划任务调度器在静态引用其他类对象后不起作用。

huangapple 未分类评论47阅读模式
英文:

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 + &quot; Loading properties file..&quot; );
			
			InputStream inputStream = new FileInputStream( new File( FMS_PROPERTY_FILE ) );

 	 		fmsProperties = new Properties();
 	 		
 	 		fmsProperties.load( inputStream );
 			
 			LOGGER.println( LOG + &quot; Properties Loaded Successfully&quot; );

 			inputStream.close();
 			
 			LOGGER.println( LOG + &quot; Reading properties values.. &quot; );
 			
 			// Timer attributes..
 	 		delayTime = Long.parseLong( fmsProperties.getProperty ( IBFT_DELAY_TIME ) );
 	 		executionTime = Long.parseLong( fmsProperties.getProperty ( IBFT_EXECUTION_TIME ) );
 	 		
 	 		LOGGER.println( LOG + &quot; IBFT DELAY &amp; EXECUTION TIME = &quot; + getDelayTime() + &quot;,&quot; + 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 + &quot; Properties values read successfully!.. &quot; );
 	 		
 	 		/******************** Database Connection.. ********************/
 	 		
 	 		LOGGER.println( LOG + &quot; Connecting to Database&quot; ); 
			 
			connection = DatabaseConnection.getDatabaseConnection().getConnection( FMS_POST_SOURCE );
			connection.setAutoCommit( false );
			 
			LOGGER.println( LOG + &quot; FMS Database Connected..&quot; );
			 
			
		} catch ( Exception e ) {
			
			LOGGER.println( LOG + &quot; Exception in Singleton block &quot; + 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&lt;String&gt; 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 + &quot; Time = &quot; + util.getSystemDate() );

		LOGGER.println( LOG + &quot; IBFT Payment Files timer starts..&quot; );
		
		try {
			
			executor();
		} 
		
		catch (Exception e) {
			
			LOGGER.println( LOG + &quot; Exception=&quot; + e.getMessage() );
		}
		
		LOGGER.println( LOG + &quot; IBFT Payment Files timer Ends..&quot; );
	}

@SuppressWarnings(&quot;static-access&quot;)
	public static void main ( String[] args ) throws SQLException {

		LOGGER.println( LOG + &quot; ---- IBFT TIMER TASK ---- &quot; );

		// 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 ); 

	}

huangapple
  • 本文由 发表于 2020年5月4日 21:03:07
  • 转载请务必保留本文链接:https://java.coder-hub.com/61592840.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定