1
2
3
4
5
6
7
8
9
10
11 package ch.qos.logback.core.rolling;
12
13 import java.util.Calendar;
14 import java.util.Date;
15
16 public class DelayerUtil {
17
18
19 static void delayUntilNextSecond(int millis) {
20 long now = System.currentTimeMillis();
21 Calendar cal = Calendar.getInstance();
22 cal.setTime(new Date(now));
23
24 cal.set(Calendar.MILLISECOND, millis);
25 cal.add(Calendar.SECOND, 1);
26
27 long next = cal.getTime().getTime();
28
29 try {
30 Thread.sleep(next - now);
31 } catch (Exception e) {
32 }
33 }
34
35 static void delayUntilNextMinute(int seconds) {
36 long now = System.currentTimeMillis();
37 Calendar cal = Calendar.getInstance();
38 cal.setTime(new Date(now));
39
40 cal.set(Calendar.SECOND, seconds);
41 cal.add(Calendar.MINUTE, 1);
42
43 long next = cal.getTime().getTime();
44
45 try {
46 Thread.sleep(next - now);
47 } catch (Exception e) {
48 }
49 }
50 }