1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.jour.rt.agent;
22
23 import java.util.Hashtable;
24
25 /***
26 * Assign number to each thread.
27 *
28 * Created on 03.12.2004
29 *
30 * Contributing Author(s):
31 *
32 * Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
33 * Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
34 *
35 * @author vlads
36 * @version $Revision: 1.3 $ ($Author: vlads $) $Date: 2004/12/07 09:04:52 $
37 */
38 public class ThreadNumber implements Event {
39 /***
40 * Stable <code>serialVersionUID</code>.
41 */
42 private static final long serialVersionUID = 29132124L;
43
44 static Hashtable threadNumber = new Hashtable(100);
45 static int count = 0;
46
47 String name;
48
49 String groupName;
50
51 int localNumber;
52
53 int groupActiveCount;
54
55 boolean daemon;
56
57
58
59 private String description;
60
61 public ThreadNumber(Thread key, int count) {
62 this.localNumber = count;
63 this.name = key.getName();
64 this.groupName = key.getThreadGroup().getName();
65 this.groupActiveCount = key.getThreadGroup().activeCount();
66 }
67
68 public static ThreadNumber getThreadNumberEvent(Thread key) {
69 ThreadNumber i = (ThreadNumber) threadNumber.get(key);
70 if (i == null) {
71 synchronized (threadNumber) {
72 i = new ThreadNumber(key, ++ count);
73 threadNumber.put(key, i);
74 }
75 }
76 return i;
77 }
78
79 public static int get(Thread key) {
80 ThreadNumber i = getThreadNumberEvent(key);
81 return i.localNumber;
82 }
83
84 public static String getUniqueThreadName(ThreadNumber thread, SystemInfoEvent sysinfo) {
85 return sysinfo.getRunID() + " " + thread.getLocalNumber() + " "+ thread.getName();
86 }
87
88 /***
89 * @return Returns the description.
90 */
91 public String getDescription() {
92 return description;
93 }
94 /***
95 * @return Returns the groupActiveCount.
96 */
97 public int getGroupActiveCount() {
98 return groupActiveCount;
99 }
100 /***
101 * @return Returns the groupName.
102 */
103 public String getGroupName() {
104 return groupName;
105 }
106 /***
107 * @return Returns the localNumber.
108 */
109 public int getLocalNumber() {
110 return localNumber;
111 }
112 /***
113 * @return Returns the name.
114 */
115 public String getName() {
116 return name;
117 }
118 }