我正在通过从属性文件获取数据来读取电子邮件消息。我正在使用计时器计划在一段时间后定期读取新消息。我该如何执行此操作?
TimerSchedule.java
public class TimeScheduler
{
public static void main(String[] args)
{
Timer timer = new Timer();
GmailConfiguration gmailConfiguration = new GmailConfiguration();
TimerTask timerTask = new TimerTask()
{
@Override
public void run()
{
gmailConfiguration.configure();
}
};
timer.scheduleAtFixedRate(timerTask, 500, 30000);
}
}
我正在从 GmailConfiguration.java 中的属性文件获取数据
这是我的 GmailConfiguration.java
public class GmailConfiguration
{
private static final Logger LOGGER = LoggerFactory.getLogger(GmailConfiguration.class);
public void configure()
{
JSONParser parser = new JSONParser();
try
{
String propertyFileName = "emailServer.properties";
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propertyFileName);
JSONObject jsonObject = (JSONObject) parser.parse(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
JSONArray jadata = (JSONArray) jsonObject.get("Servers");
int len = jadata.size();
AccessMailMessages readGmail = new AccessMailMessages();
JSONObject server;
String name;
String host;
String username;
String password;
int port;
String folderName;
for (int i = 0; i < len; i++)
拉莫斯之舞
相关分类