2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.apache.log4j.or;
20 import org.apache.log4j.Layout;
24 Render {@link ThreadGroup} objects in a format similar to the
25 information output by the {@link ThreadGroup#list} method.
26 @author Ceki Gülcü
28 public class ThreadGroupRenderer implements ObjectRenderer {
31 ThreadGroupRenderer() {
35 Render a {@link ThreadGroup} object similar to the way that the
36 {@link ThreadGroup#list} method output information.
38 <p>The output of a simple program consisting of one
39 <code>main</code> thread is:
41 java.lang.ThreadGroup[name=main, maxpri=10]
45 <p>The boolean value in thread information is the value returned
46 by {@link Thread#isDaemon}.
50 String doRender(Object o) {
51 if(o instanceof ThreadGroup) {
52 StringBuffer sbuf = new StringBuffer();
53 ThreadGroup tg = (ThreadGroup) o;
54 sbuf.append("java.lang.ThreadGroup[name=");
55 sbuf.append(tg.getName());
56 sbuf.append(", maxpri=");
57 sbuf.append(tg.getMaxPriority());
59 Thread[] t = new Thread[tg.activeCount()];
61 for(int i = 0; i < t.length; i++) {
62 sbuf.append(Layout.LINE_SEP);
63 sbuf.append(" Thread=[");
64 sbuf.append(t[i].getName());
66 sbuf.append(t[i].getPriority());
68 sbuf.append(t[i].isDaemon());
71 return sbuf.toString();
74 // this is the best we can do
76 } catch(Exception ex) {