The idea is as follows: I add an entry to the database, but before that I want to “add” the adding process a little, displaying the following values in the console: 10% ... 20% ... 30% ... etc. until the end ... at the end to bring out the word "Added!". Each percent must be withdrawn at intervals of a second, i.e. first a second without information, then after a second output 10% ..., after another second 20% ... and so on. It seems everything works out, but the word "Added" crashes right at the very beginning of the program, and indeed the whole program flies ahead with its life without waiting until it works until the end of the code block with the timer. Please explain how to write correctly so that the program waits until the end of work in the timer block and only then, depending on the success or failure of adding the record, worked further.
import java.util.Timer; import java.util.TimerTask; public class MyTimer{ public static int proc = 0; public static void main(String[] args){ final Timer writeTime = new Timer(); writeTime.schedule(new TimerTask() { @Override public void run(){ if(proc < 100) { proc = proc + 10; System.out.print(proc + "%..."); } } },1000,1000); System.out.println("Добавлен"!); } }