01: /**
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */package com.tc.util;
04:
05: import EDU.oswego.cs.dl.util.concurrent.Latch;
06:
07: import java.util.Timer;
08: import java.util.TimerTask;
09:
10: /**
11: * 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
12: * to set the name of the background execution thread so that it can be identified properly in a thread dump
13: */
14: public class TCTimerImpl extends Timer implements TCTimer {
15:
16: // NOTE: There isn't a cstr with a default for isDaemon on purpose. Best to think about this and be explicit
17: public TCTimerImpl(final String threadName, boolean isDaemon) {
18: super (isDaemon);
19:
20: final Latch proceed = new Latch();
21:
22: TimerTask nameSetter = new TimerTask() {
23: public void run() {
24: Thread.currentThread().setName(threadName);
25: proceed.release();
26: }
27: };
28:
29: schedule(nameSetter, 0L);
30:
31: try {
32: proceed.acquire();
33: } catch (InterruptedException e) {
34: // ignore
35: }
36: }
37:
38: }
|