donaldp 02/04/10 03:51:26
Modified: threadcontext/src/java/org/apache/excalibur/threadcontext
ThreadContext.java LayeredThreadContext.java
Log:
Each ThreadContext may only be active in one thread at a time now.
Revision Changes Path
1.3 +26 -2
jakarta-avalon-excalibur/threadcontext/src/java/org/apache/excalibur/threadcontext/ThreadContext.java
Index: ThreadContext.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/threadcontext/src/java/org/apache/excalibur/threadcontext/ThreadContext.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ThreadContext.java 9 Apr 2002 09:20:54 -0000 1.2
+++ ThreadContext.java 10 Apr 2002 10:51:26 -0000 1.3
@@ -57,6 +57,13 @@
private final HashMap m_map;
/**
+ * This variable is set to the thread that the ThreadContext
+ * is currently active on. A ThreadContext can not be active
+ * on multiple threads at the same time.
+ */
+ private Thread m_activeThread;
+
+ /**
* Retrieve the ThreadContext associated with the current thread.
*
* @return the ThreadContext associated with the current thread.
@@ -73,10 +80,11 @@
* on new <code>ThreadContext</code> (if not null).
*
* @param threadContext the new ThreadContext
- * @exception SecurityException if the caller does not have permission
to set thread pool
+ * @throws SecurityException if the caller does not have permission to
set thread pool
+ * @throws IllegalArgumentException if the specified context is already
bound to a thread
*/
public static void setThreadContext( final ThreadContext threadContext )
- throws SecurityException
+ throws SecurityException, IllegalArgumentException
{
final SecurityManager securityManager = System.getSecurityManager();
if( null != securityManager )
@@ -84,6 +92,12 @@
securityManager.checkPermission( c_setThreadContext );
}
+ if( threadContext.isActive() )
+ {
+ throw new IllegalArgumentException( "Specified ThreadContext is
already " +
+ "bound to a thread" );
+ }
+
final ThreadContext oldThreadContext =
(ThreadContext)c_context.get();
if( null != oldThreadContext )
{
@@ -131,11 +145,20 @@
}
/**
+ * Determine if ThreadContext is active (ie bound to a thread).
+ */
+ private boolean isActive()
+ {
+ return ( null != m_activeThread );
+ }
+
+ /**
* Utility method to call activate on policy object.
*/
private void activate()
{
m_policy.activate( m_accessor );
+ m_activeThread = Thread.currentThread();
}
/**
@@ -143,6 +166,7 @@
*/
private void deactivate()
{
+ m_activeThread = null;
m_policy.deactivate( m_accessor );
}
1.3 +23 -1
jakarta-avalon-excalibur/threadcontext/src/java/org/apache/excalibur/threadcontext/LayeredThreadContext.java
Index: LayeredThreadContext.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/threadcontext/src/java/org/apache/excalibur/threadcontext/LayeredThreadContext.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LayeredThreadContext.java 9 Apr 2002 09:20:54 -0000 1.2
+++ LayeredThreadContext.java 10 Apr 2002 10:51:26 -0000 1.3
@@ -65,6 +65,13 @@
private final ArrayList m_layers = new ArrayList();
/**
+ * This variable is set to the thread that the ThreadContext
+ * is currently active on. A ThreadContext can not be active
+ * on multiple threads at the same time.
+ */
+ private Thread m_activeThread;
+
+ /**
* Retrieve the LayeredThreadContext associated with the current thread.
*
* @return the LayeredThreadContext associated with the current thread.
@@ -81,7 +88,8 @@
* on new <code>LayeredThreadContext</code> (if not null).
*
* @param threadContext the new LayeredThreadContext
- * @exception SecurityException if the caller does not have permission
to set thread pool
+ * @throws SecurityException if the caller does not have permission to
set thread pool
+ * @throws IllegalArgumentException if the specified context is already
bound to a thread
*/
public static void setThreadContext( final LayeredThreadContext
threadContext )
throws SecurityException
@@ -92,6 +100,12 @@
securityManager.checkPermission( c_setThreadContextPermission );
}
+ if( threadContext.isActive() )
+ {
+ throw new IllegalArgumentException( "Specified ThreadContext is
already " +
+ "bound to a thread" );
+ }
+
final LayeredThreadContext oldThreadContext =
(LayeredThreadContext)c_context.get();
if( null != oldThreadContext )
{
@@ -255,6 +269,14 @@
}
return context;
+ }
+
+ /**
+ * Determine if ThreadContext is active (ie bound to a thread).
+ */
+ private boolean isActive()
+ {
+ return ( null != m_activeThread );
}
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>