[jboss-cvs] JBossAS SVN: r92016 - projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Aug 5 15:16:05 EDT 2009
Author: david.lloyd at jboss.com
Date: 2009-08-05 15:16:05 -0400 (Wed, 05 Aug 2009)
New Revision: 92016
Added:
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ThreadFormattedNameExecutor.java
Modified:
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossExecutors.java
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossThread.java
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossThreadFactory.java
Log:
Formatted thread name executor
Modified: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossExecutors.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossExecutors.java 2009-08-05 15:48:28 UTC (rev 92015)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossExecutors.java 2009-08-05 19:16:05 UTC (rev 92016)
@@ -188,6 +188,18 @@
}
/**
+ * Create a direct executor which changes the thread name for the duration of a task using a formatted name.
+ * The thread must be a {@link JBossThread}.
+ *
+ * @param delegate the executor to delegate to
+ * @param newName the thread name to use
+ * @return the new direct executor
+ */
+ public static DirectExecutor threadFormattedNameExecutor(final DirectExecutor delegate, final String newName) {
+ return new ThreadFormattedNameExecutor(newName, delegate);
+ }
+
+ /**
* Create a direct executor which adds a note to the thread name for the duration of a task.
*
* @param delegate the executor to delegate to
@@ -640,7 +652,7 @@
return new CompositeTask(runnables.toArray(new Runnable[runnables.size()]));
}
- private static void checkAccess(Permission permission) {
+ static void checkAccess(Permission permission) {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(permission);
Modified: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossThread.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossThread.java 2009-08-05 15:48:28 UTC (rev 92015)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossThread.java 2009-08-05 19:16:05 UTC (rev 92016)
@@ -31,6 +31,7 @@
private static final Logger log = Logger.getLogger(JBossThread.class);
private InterruptHandler interruptHandler;
+ private ThreadNameInfo threadNameInfo;
/**
* Construct a new instance.
@@ -179,4 +180,24 @@
thread.interruptHandler = newInterruptHandler;
}
}
+
+ /**
+ * Get the thread name information. This includes information about the thread's sequence number and so forth.
+ *
+ * @return the thread name info
+ */
+ public ThreadNameInfo getThreadNameInfo() {
+ return threadNameInfo;
+ }
+
+ /**
+ * Set the thread name information. This includes information about the thread's sequence number and so forth.
+ *
+ * @param threadNameInfo the new thread name info
+ * @throws SecurityException if the calling thread is not allowed to modify this thread
+ */
+ public void setThreadNameInfo(final ThreadNameInfo threadNameInfo) throws SecurityException {
+ checkAccess();
+ this.threadNameInfo = threadNameInfo;
+ }
}
Modified: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossThreadFactory.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossThreadFactory.java 2009-08-05 15:48:28 UTC (rev 92015)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossThreadFactory.java 2009-08-05 19:16:05 UTC (rev 92016)
@@ -105,6 +105,7 @@
} else {
thread = new JBossThread(threadGroup, target);
}
+ thread.setThreadNameInfo(nameInfo);
thread.setName(nameInfo.format(thread, namePattern));
if (initialPriority != null) thread.setPriority(initialPriority.intValue());
if (daemon != null) thread.setDaemon(daemon.booleanValue());
Copied: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ThreadFormattedNameExecutor.java (from rev 91879, projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ThreadNameExecutor.java)
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ThreadFormattedNameExecutor.java (rev 0)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ThreadFormattedNameExecutor.java 2009-08-05 19:16:05 UTC (rev 92016)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.threads;
+
+class ThreadFormattedNameExecutor implements DirectExecutor {
+
+ private final String nameFormat;
+ private final DirectExecutor delegate;
+
+ ThreadFormattedNameExecutor(final String nameFormat, final DirectExecutor delegate) {
+ this.nameFormat = nameFormat;
+ this.delegate = delegate;
+ }
+
+ public void execute(final Runnable command) {
+ final JBossThread thr = JBossThread.currentThread();
+ final String oldName = thr.getName();
+ thr.setName(thr.getThreadNameInfo().format(thr, nameFormat));
+ try {
+ delegate.execute(command);
+ } finally {
+ thr.setName(oldName);
+ }
+ }
+
+ public String toString() {
+ return String.format("%s format=\"%s\" -> %s", super.toString(), nameFormat, delegate);
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list