KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > util > TCTimerImpl


1 /**
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.util;
5
6 import EDU.oswego.cs.dl.util.concurrent.Latch;
7
8 import java.util.Timer JavaDoc;
9 import java.util.TimerTask JavaDoc;
10
11 /**
12  * A wrapper around java.util.Timer. Someone might add more it more in the future, but for now all I'm adding is a way
13  * to set the name of the background execution thread so that it can be identified properly in a thread dump
14  */

15 public class TCTimerImpl extends Timer JavaDoc implements TCTimer {
16
17   // NOTE: There isn't a cstr with a default for isDaemon on purpose. Best to think about this and be explicit
18
public TCTimerImpl(final String JavaDoc threadName, boolean isDaemon) {
19     super(isDaemon);
20
21     final Latch proceed = new Latch();
22
23     TimerTask JavaDoc nameSetter = new TimerTask JavaDoc() {
24       public void run() {
25         Thread.currentThread().setName(threadName);
26         proceed.release();
27       }
28     };
29
30     schedule(nameSetter, 0L);
31
32     try {
33       proceed.acquire();
34     } catch (InterruptedException JavaDoc e) {
35       // ignore
36
}
37   }
38
39 }
40
Popular Tags