View Javadoc
1   /**
2    * Copyright By Grandsoft Company Limited.  
3    * 2012-8-2 下午05:51:22
4    */
5   package gboat2.base.core;
6   
7   import org.slf4j.Logger;
8   import org.slf4j.LoggerFactory;
9   
10  /**
11   * 
12   * Activator内部跨bundle线程,协助处理bundle间bean的依赖等待
13   * @author lysming
14   * @since jdk1.6
15   * @date 2012-8-2
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  }