1
2
3
4
5 package gboat2.base.core;
6
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9
10
11
12
13
14
15
16
17
18
19 public abstract class ActivatorInnerThread extends Thread {
20
21 private Logger logger = LoggerFactory.getLogger(ActivatorInnerThread.class);
22
23 private long wait = 10000;
24
25 public ActivatorInnerThread() {
26 super();
27 }
28
29 public ActivatorInnerThread(long wait) {
30 this.wait = wait;
31 }
32
33 public final void run() {
34 boolean finished = false;
35 int times = 0;
36 while (!finished) {
37 try {
38 sleep(wait);
39 } catch (Exception e) {
40 e.printStackTrace();
41 }
42 try {
43 finished = task();
44 } catch (Exception e) {
45 e.printStackTrace();
46 if (times++ == 10) {
47 logger.error("give up at try 10 times.", e);
48 break;
49 }
50 }
51 }
52 }
53
54 public abstract boolean task();
55 }