Use Timertask to perform tasks per month.

zhaozj2021-02-16  51

/ ** *

Title: SubbillingTimer *

Description: Overview: Set timing send packets.

Interpretation of some attribute variables: Interpretation of partial functions / method: 1. Settimer () Sets the specific time when performing tasks ._timer.schedule (New SubbillingTimer (), Date); 2. Subbilling () Binding billing package and send 3.Run () is executed to a specific time, and calls subbilling (), then call SetTimer () to set the specific time of the next month * /

Import java.util.calendar; import java.util.date; import java.util.timertask; import java.util.timer;

Public class subbillingtimer extends Timertask {private timer_timer; private int _day = 21; private int _Hour = 2;

Public subbillingtimer () {}

Public void Run () {if (Initconfigure.debug_level> 8) {system.out.println ("- Sub Billing Timer Start Run ...");} Subbilling (); setTimer (_Day, _ Hour, true);}

Public void settimer (int day, int hour) {settimer (day, hour, false);}

Public void settimer (int days, int hour, boolean bgnextmonth) {_day = day; _Hour = hour

Calendar Cale = Calendar.GetInstance (); // gets a calendar useing the default time zone and local. If (bgnextMonth || Cale.get (Cale.day_of_month)> = day) {// More than this day or next month True, the setting time task is next month Cale.set (Cale.Month) 1);} Date Date = New Date (Cale.Year) - 1900, Cale.year .get (cale.month), day, hour, 0); if (_timer == null) {_timer = new timer ();} system.out.println ("Set Subbilling Timer [" Date ": ( date.getTime () - System.currentTimeMillis ()) "]:" _timer.toString ()); _timer.schedule (new SubBillingTimer (), date); // Schedules the specified task for execution at the specified time. set time }

Public void stop () {this.cancel (); _timer.cancel ();} private void subbilling () {}

Public static void main (String [] args) {subbillingtimer sub_timer = new subbillingtimer (); sub_timer.settimer (21, 2);}}

转载请注明原文地址:https://www.9cbs.com/read-19218.html

New Post(0)