com.sun.jaw.impl.agent.services.light
Class ThreadAllocatorSrv

java.lang.Object
  |
  +--com.sun.jaw.impl.agent.services.light.ThreadAllocatorSrv

public class ThreadAllocatorSrv
extends java.lang.Object
implements ThreadAllocatorSrvIf

This class provides a simple implementation of a thread allocator. It returns a new Thread() to the requestor.

M-beans can get a pointer to the thread allocator service through the framework object using the ThreadAllocatorSrvIf getThreadAllocatorSrvIf() public method.

The ThreadAllocatorSrvIf interface defines Thread obtainThread(...) methods that follow Thread constructor prototypes with one additional parameter, named requestorId (java.lang.Object), that identifies the requestor.
M-Beans and services of JDMK use their ObjectName as requestor identifier.

See Also:
Runnable, Thread, ThreadAllocatorSrvIf

Constructor Summary
ThreadAllocatorSrv()
           
 
Method Summary
 java.lang.String[] getActiveThreadNameArray()
          Returns an array containing all names of active Thread.
 java.lang.Thread obtainThread(java.lang.Object requestorId)
          Allocates a new Thread object.
 java.lang.Thread obtainThread(java.lang.Object requestorId, java.lang.Runnable target)
          Allocates a new Thread object.
 java.lang.Thread obtainThread(java.lang.Object requestorId, java.lang.Runnable target, java.lang.String name)
          Allocates a new Thread object.
 java.lang.Thread obtainThread(java.lang.Object requestorId, java.lang.String name)
          Allocates a new Thread object.
 java.lang.Thread obtainThread(java.lang.Object requestorId, java.lang.ThreadGroup group, java.lang.Runnable target)
          Allocates a new Thread object.
 java.lang.Thread obtainThread(java.lang.Object requestorId, java.lang.ThreadGroup group, java.lang.Runnable target, java.lang.String name)
          Allocates a new Thread object with requestorId as the requestor identifier, target as its run object, and the specified name as its name; the thread is assigned to the thread group referred to by group.
 java.lang.Thread obtainThread(java.lang.Object requestorId, java.lang.ThreadGroup group, java.lang.String name)
          Allocates a new Thread object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadAllocatorSrv

public ThreadAllocatorSrv()
Method Detail

obtainThread

public java.lang.Thread obtainThread(java.lang.Object requestorId)
Allocates a new Thread object. This method has the same effect as obtainThread(requestorId, null, null, gname), where gname is an automatically generated name. Automatically generated names are of the form "Thread-"+n, where n is an integer.

Threads created this way must have overridden their run method to actually do anything. An example illustrating this method being used follows:


     class threadtest {
         public threadtest() {
         }
         public void initCmf(Framework cmf,ObjectName name){

             Thread t1 = cmf.getThreadAllocatorSrvIf().obtainThread(name);  
             if (t1 != null){
                 System.out.println("new Thread() succeed");
                 cmf.addObject(this, name);
             } else {
                 System.out.println("new Thread() failed"); 
             }
         }

 
Specified by:
obtainThread in interface ThreadAllocatorSrvIf
Parameters:
resquestorId - The requestor's identifier.
See Also:
obtainThread(java.lang.Object, java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)

obtainThread

public java.lang.Thread obtainThread(java.lang.Object requestorId,
                                     java.lang.Runnable target)
Allocates a new Thread object. This method has the same effect as obtainThread(requestorId, null, target, gname), where gname is an automatically generated name. Automatically generated names are of the form "Thread-"+n, where n is an integer.
Specified by:
obtainThread in interface ThreadAllocatorSrvIf
Parameters:
resquestorId - The requestor's identifier.
target - the object whose run method is called.
See Also:
obtainThread(java.lang.Object, java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)

obtainThread

public java.lang.Thread obtainThread(java.lang.Object requestorId,
                                     java.lang.ThreadGroup group,
                                     java.lang.Runnable target)
Allocates a new Thread object. This method has the same effect as obtainThread(requestorId, group, target, gname), where gname is an automatically generated name. Automatically generated names are of the form "Thread-"+n, where n is an integer.
Specified by:
obtainThread in interface ThreadAllocatorSrvIf
Parameters:
resquestorId - The requestor's identifier.
group - the thread group.
target - the object whose run method is called.
Throws:
java.lang.SecurityException - if the current thread cannot create a thread in the specified thread group.
See Also:
obtainThread(java.lang.Object, java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)

obtainThread

public java.lang.Thread obtainThread(java.lang.Object requestorId,
                                     java.lang.String name)
Allocates a new Thread object. This method has the same effect as obtainThread(requestorId, null, null, name).
Specified by:
obtainThread in interface ThreadAllocatorSrvIf
Parameters:
resquestorId - The requestor's identifier.
name - the name of the new thread.
See Also:
obtainThread(java.lang.Object, java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)

obtainThread

public java.lang.Thread obtainThread(java.lang.Object requestorId,
                                     java.lang.ThreadGroup group,
                                     java.lang.String name)
Allocates a new Thread object. This method has the same effect as obtainThread(requestorId, group, null, name)
Specified by:
obtainThread in interface ThreadAllocatorSrvIf
Parameters:
resquestorId - The requestor's identifier.
group - the thread group.
name - the name of the new thread.
Throws:
java.lang.SecurityException - if the current thread cannot create a thread in the specified thread group.
See Also:
obtainThread(java.lang.Object, java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)

obtainThread

public java.lang.Thread obtainThread(java.lang.Object requestorId,
                                     java.lang.Runnable target,
                                     java.lang.String name)
Allocates a new Thread object. This method has the same effect as obtainThread(requestorId, null, target, name).
Specified by:
obtainThread in interface ThreadAllocatorSrvIf
Parameters:
resquestorId - The requestor's identifier.
target - the object whose run method is called.
name - the name of the new thread.
See Also:
obtainThread(java.lang.Object, java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)

obtainThread

public java.lang.Thread obtainThread(java.lang.Object requestorId,
                                     java.lang.ThreadGroup group,
                                     java.lang.Runnable target,
                                     java.lang.String name)
Allocates a new Thread object with requestorId as the requestor identifier, target as its run object, and the specified name as its name; the thread is assigned to the thread group referred to by group.

If group is not null, the checkAccess method of that thread group is called with no arguments; this may result in throwing a SecurityException. If group is null, the new process belongs to the same group as the thread that is creating the new thread.

If the target argument is not null, the run method of the target is called when this thread is started. If the target argument is null, this thread's run method is called when this thread is started.

The priority of the newly created thread is set equal to the priority of the thread creating it, that is, the currently running thread. The method setPriority may be used to change the priority to a new value.

The newly created thread is initially marked as being a daemon thread if and only if the thread creating it is currently marked as a daemon thread. The method setDaemon may be used to change whether or not a thread is a daemon.

Specified by:
obtainThread in interface ThreadAllocatorSrvIf
Parameters:
resquestorId - The requestor's identifier.
group - the thread group.
target - the object whose run method is called.
name - the name of the new thread.
Throws:
java.lang.SecurityException - if the current thread cannot create a thread in the specified thread group.

getActiveThreadNameArray

public java.lang.String[] getActiveThreadNameArray()
Returns an array containing all names of active Thread.
Returns:
The array of names of active Thread.