l ๐Ÿค– ์ฝ”๋“œ l

๊ธฐ์ƒ์ฒญ ๋‚ ์”จapi ์ •ํ•ด์ง„ ์‹œ๊ฐ„๊ฐ„๊ฒฉ์œผ๋กœ ์—…๋ฐ์ดํŠธ ํ•˜๊ธฐ (์ž๋ฐ”ํƒ€์ด๋จธ Java Timer ๊ธฐ๋Šฅ ์‚ฌ์šฉ๋ฒ•)

์ฝ”๋“œ๊ทธ๋ฆผ 2020. 5. 21.
๋ฐ˜์‘ํ˜•

์ž๋ฐ” ํƒ€์ด๋จธ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•ด์„œ ์ •ํ•ด์ง„ ์‹œ๊ฐ„๊ฐ„๊ฒฉ์œผ๋กœ ํ”„๋กœ๊ทธ๋žจ์ด ์‹คํ–‰๋˜๊ณ  

๋ฐ์ดํ„ฐ๊ฐ€ ์—…๋ฐ์ดํŠธ ๋  ์ˆ˜ ์žˆ๊ฒŒ ๋งŒ๋“ค์—ˆ์–ด์š”!!

 

1000*5   5์ดˆ

1000*60   1๋ถ„

1000*60*60  1์‹œ๊ฐ„

1000*60*60*24  1์ผ

 

 

//ํ”„๋กœ์ ํŠธ ํ†ต์œผ๋กœ ์˜ฌ๋ ค๋‘” ๊นƒํ—ˆ๋ธŒ ์ฃผ์†Œ์ž…๋‹ˆ๋‹ค.

๋‹ค๋ฅธ ๋‚ด์šฉ์ด ๊ถ๊ธˆํ•˜์‹œ๋‹ค๋ฉด ํ™•์ธ ํ•ด ์ฃผ์„ธ์š”.

github.com/Joowon0220/weather.git

package com.weather03.mvc;

import java.io.IOException;
import java.util.Calendar;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import org.json.simple.parser.ParseException;

public class weatherControl extends TimerTask {
	public void run() {
		Calendar date = Calendar.getInstance();
		String stamp = date.get(Calendar.HOUR_OF_DAY) + ":" + date.get(Calendar.MINUTE) + ":"
				+ date.get(Calendar.SECOND) + ":" + date.get(Calendar.MILLISECOND);
		System.out.println(stamp + " " + "Generating report");
		
		
		// List<VillageWeather> datalist = new List<VillageWeather>;
		VillageWeatherJson vlist = new VillageWeatherJson();
		// ๊ธฐ์ƒ๋ฐ์ดํ„ฐ๋ฅผ JSON์„ arrayList ํ˜•ํƒœ๋กœ ๋ฐ›์•„ VillageWeather์— ์ €์žฅ
		List<VillageWeather> vw;
	
		try {
			vw = vlist.getVillageWeather();
			VillageWeatherDAO vwDao = new VillageWeatherDAO();
			vwDao.insertVillageWeather(vw);

		} catch (IOException | ParseException | ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ ‘์†์— ๊ด€๋ จํ•˜๋Š”๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค๊ณ  ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ž…๋ ฅ
	}

	public static void main(String[] args) {

		Timer timer = new Timer();
		Calendar date = Calendar.getInstance();
		date.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY

		);

		date.set(Calendar.HOUR, 0);
		date.set(Calendar.MINUTE, 0);
		date.set(Calendar.SECOND, 0);
		date.set(Calendar.MILLISECOND, 0);
		// Schedule to run every Sunday in midnight
		timer.schedule(new weatherControl(), date.getTime(),
				// 1000 * 5
				// 1000 * 60 * 60 * 24
				1000 * 60* 60);

	}
}
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€

๐Ÿ’ฒ ์ถ”์ฒœ ๊ธ€