Mercurial Hosting > nabble
comparison src/fschmidt/util/executor/ThreadTimer.java @ 68:00520880ad02
add fschmidt source
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Sun, 05 Oct 2025 17:24:15 -0600 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 67:9d0fefce6985 | 68:00520880ad02 |
|---|---|
| 1 package fschmidt.util.executor; | |
| 2 | |
| 3 import java.util.Date; | |
| 4 import java.util.Map; | |
| 5 import java.util.Set; | |
| 6 import java.util.concurrent.ConcurrentHashMap; | |
| 7 import java.util.concurrent.TimeUnit; | |
| 8 import java.util.concurrent.BlockingQueue; | |
| 9 | |
| 10 | |
| 11 public final class ThreadTimer implements RunnableWrapper { | |
| 12 private final Map<Thread,Date> map = new ConcurrentHashMap<Thread,Date>(); | |
| 13 | |
| 14 @Override public Runnable wrap(final Runnable command) { | |
| 15 return new Runnable(){public void run(){ | |
| 16 map.put(Thread.currentThread(),new Date()); | |
| 17 try { | |
| 18 command.run(); | |
| 19 } finally { | |
| 20 map.remove(Thread.currentThread()); | |
| 21 } | |
| 22 }}; | |
| 23 } | |
| 24 | |
| 25 public Date whenRun(Thread thread) { | |
| 26 return map.get(thread); | |
| 27 } | |
| 28 | |
| 29 public Set<Thread> getThreads() { | |
| 30 return map.keySet(); | |
| 31 } | |
| 32 } |
