Good day.
There is a code:
package ru.copy; public class workProgram { public static void main(String[] args) throws IOException { //МОЙ код для копирования данных } } My program copies files from one folder to another. The fact is that files will be periodically poured into the source folder, this will happen for 15-20 hours and you need to copy ALL the files. In addition, these files in the source folder will be there for 1 hour, and then deleted (and therefore need to copy them from there).
How to make a permanent code execution and shutdown procedure?
The simplest thing is to make an eternal cycle:
public class workProgram { public static void main(String[] args) throws IOException { int a = 1; while (true) { //МОЙ код для копирования данных } } } Then the program goes into the eternal cycle, it works and the files are copied. But how to make the correct stop of such a code? And no more accurate solutions?
Yes, I tried launching by time intervals:
Timer timer = new Timer(); TimerTask timerTask = new TimerTask() { public void run() { //мой код } }; timer.schedule(timerTask, 5000, 10000); //первое число - когда он запуститься, второе - через сколько будет повторяться This is incorrect, because the procedure may not have time to complete by the required time and a separate thread will start, which can lead to an error, and again - how to stop it?
PS probably, in my writing style, you understood that I was a beginner, so I beg you to give detailed answers with comments (I tried to ask the most clear question).
cron jobor something like that - Barmaley