マルチスレッドタイマーは3秒ごとに実行されます
1 Timer timer = new Timer(); 2 timer.schedule(new TimerTask(){ 3 // runメソッド内のステートメントは、スケジュールされたタスクが実行されたときに実行されるステートメントです 4 public void run(){ 5 System.out.println ( "11232" ); 6 7 try { 8 // Call method 9 new ClientAxis2TestCurAllData(); 10 } catch (Exception e){ 11 // TODO自動生成されたcatchブロック 12 e.printStackTrace(); 13 } 14 15 } 16 // 3秒後に実行を開始し、2秒ごとに1回実行することを示します 17 }、0、3000);
マルチスレッドタイマーは毎日0:00に実行されます
1 public static void main(String [] args){ 2 new TimerManager(); 3 } 4 5 // 時間间间隔(一天) 6 プライベート 静的 最終 long PERIOD_DAY = 24 * 60 * 60 * 1000 ; 7 public TimerManager(){ 8 Calendar calendar = Calendar.getInstance(); 9 calendar.set(Calendar.HOUR_OF_DAY、1); // 凌chen1点 10 calendar.set(Calendar.MINUTE、0 ); 11 calendar.set(Calendar.SECOND、0); 12 Date date = calendar.getTime(); // スケジュールされたタスクの最初の実行の時間13 // スケジュールされたタスク の最初の実行の時間が現在の時間よりも短い場合 14 // この時点で、最初の実行のタイミングこのタスクが次の時点で実行されるように、タスク時間に1日を追加します。日を追加しない場合、タスクはすぐに実行されます。 15 if(date.before(new Date())){ 16 date = this .addDay(date、1 ); 17 } 18 Timer timer = new Timer(); 19 // 呼び出されるメソッド 20 Task task = new Task( ); 21 // 指定されたタスクをスケジュールして、指定された時間に繰り返し固定遅延実行を開始します。 22 timer.schedule(task、date、PERIOD_DAY); 23 } 24 // 增加または减少天数 25 public Date addDay(Date date、int num){ 26 Calendar startDT = Calendar.getInstance(); 27 startDT.setTime(date); 28 startDT.add(Calendar.DAY_OF_MONTH、num); 29 return startDT.getTime();
期間内のJavaマッチ時間
1 SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ); 2 3 4 5 // 開始時刻 6 Calendar begin = Calendar.getInstance(); 7 begin.setTime(new Date()); 8 begin.set(Calendar.MINUTE、begin.get(Calendar.MINUTE)-30 ); 9 10 11 // 時間を比較 12 日付nowTime = dateFormat.parse( "2020-04-17 10:12:15" ) ; 13 14 //日付nowTime = dateFormat.parse((new ClientAxis2TestCurAllData())。getSubUtilSimple(content、rgex)); 15 カレンダーの日付= Calendar.getInstance(); 16 date.setTime(nowTime); 17 18 // 结束时间 19 Calendar dateend = Calendar.getInstance(); 20 dateend.setTime(new Date()); 21 22 23 if(date.after(begin)&& date.before(dateend)){ 24 System.out.println( "000000000000000000000000000000000000000000000000000"); 25 26 27 // mysqldemo.add((new ClientAxis2TestCurAllData())。getSubUtilSimple(content、rgex)、(new ClientAxis2TestCurAllData())。getSubUtilSimple(content、rgex1)、(new ClientAxis2TestCurAllData())。getSubUtilSimple(content、rgex2) 、(new ClientAxis2TestCurAllData())。getSubUtilSimple(content、rgex3)、(new TestStringToXml())。getSubUtilSimple(content、rgex4)); 28 System.out.println(i); 29 30 31 }
文字列文字列間のデータを取得する正規表現
1つの パッケージcom.xml; 2 3 4 import java.util.ArrayList; 5 import java.util.List; 6 インポートjava.util.regex.Matcher; 7 インポートjava.util.regex.Pattern; 8 9 / ** 10 *正则取中间数 11 * @author lenovo 12 * 13 * / 14 15 public class TestStringToXml { 16 17 18 public static void main(String [] args){ 19 String str = "record:data_time2019-12-13 14:37:30.0gateway_logo867726033797152sensor_name1channel_name401value22.0" ; 20 // 文字列str = "abc3443abcfgjhgabcgfjabc"; 21 文字列rgex = "data_time(。*?)gateway_logo" ; 22 23 文字列rgex1 = "gateway_logo(。*?)sensor_name" ; 24 25 文字列rgex2 = "sensor_name(。*?)channel_name" ; 26 27 文字列rgex3 = "channel_name(。*?)value" ; 28 29 文字列rgex4 = "value(。*)" ; 30 31 32 System.out。TestStringToXml())。getSubUtil(str、rgex)); 33 34 List <String>リスト=(new TestStringToXml())。getSubUtil(str、rgex); 35 のために(文字列:リスト){ 36 のSystem.out.println(列)。 37 } 38 39 System.out.println((new TestStringToXml())。getSubUtilSimple(str、rgex)); 40 41 System.out.println((new TestStringToXml())。getSubUtilSimple(str、rgex1)); 42 43 44 System.out.println((new TestStringToXml())。getSubUtilSimple(str、rgex2)); 45 46 47 System.out.println((new TestStringToXml())。GetSubUtilSimple(str、rgex3)); 48 49 50 System.out.println((new TestStringToXml())。GetSubUtilSimple(str、rgex4)); 51 52 53 } 54 55 56 / ** 57 *正規表現は、2つの指定された文字列間のコンテンツに一致します 58 * @param soap 59 * @return 60 * / 61 public List <String> getSubUtil(String soap、String rgex){ 62 リスト<String>リスト=new ArrayList <String> (); 63 Pattern pattern = Pattern.compile(rgex); // 一致パターン 64 Matcher m = pattern.matcher(soap); 65 while (m.find()){ 66 int i = 1 ; 67 list.add(m.group(i)); 68 i ++ ; 69 } 70 return list; 71 } 72 73 / ** 74 *一致するものが複数ある場合、最初の文字列を返す、メソッドgetSubUtil 75 * @param soapと 同じ 76 * @param rgex 77 * @return 78 * / 79 public String getSubUtilSimple(String soap、String rgex){ 80 Pattern pattern = Pattern.compile(rgex); // 比較配的模式 81 マッチャーm = pattern.matcher(soap); 82 while (m.find()){ 83 return m.group(1 ); 84 } 85 return "" ; 86 } 87 88 89 90 91 92 } 93 94 95