- java.lang.Object
- 
- jdk.management.resource.ResourceContextFactory
 
- 
 
 public final class ResourceContextFactory extends Object The ResourceContextFactory provides access to ResourceContext functions. The factory provides methods to:- Return the ResourceContextFactoryinstance and checks if the API is accessible to the caller
- Check if ResourceContexts are enabled
- Return a new ResourceContext
- Return a ResourceContext by name
- Return the ResourceContext bound to the current thread
- Return the UnassignedContext used for all unbound threads
- Return the TotalsContext that tracks totals of all contexts
- Return a Stream of the ResourceContexts
- Return the supported ResourceTypes
 getInstancemethod checks if there is a SecurityManager installed and theRuntimePermission("jdk.management.resource.getResourceContextFactory")is allowed. The reference to the ResourceContextFactory is a capability and should not be shared.Threads that exist when the ResourceContextFactory is initialized are bound to the unassignedContextif they are not system threads. System threads ( with(thread.getThreadGroup().getParent() == null) are not bound to theunassignedContext. The resources used by system threads are not recorded.- Since:
- 8u40
 
- Return the 
- 
- 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Stream<ResourceContext>contexts()Returns a Stream of the existing ResourceContexts.ResourceContextcreate(String name)Create a new ResourceContext.static ResourceContextFactorygetInstance()Returns the factory for ResourceContexts if enabled in the runtime.ResourceRequestgetResourceRequest(ResourceType type)Returns the ResourceRequest for the current ResourceContext and ResourceType.ResourceContextgetThreadContext()Returns the ResourceContext associated with the current thread.ResourceContextgetThreadContext(Thread thread)Returns the ResourceContext associated with the thread.ResourceContextgetTotalsContext()Returns a ResourceContext that provides the totals for all ResourceContexts.ResourceContextgetUnassignedContext()Returns the ResourceContext that is the default when a thread is not associated with a ResourceContext.static booleanisEnabled()Returnstrueif and only if ResourceManagement is enabled.ResourceContextlookup(String name)Returns the ResourceContext given by name.Set<ResourceType>supportedResourceTypes()Returns a read-only Set of the builtin ResourceTypes available in the current runtime.
 
- 
- 
- 
Method Detail- 
isEnabledpublic static boolean isEnabled() Returnstrueif and only if ResourceManagement is enabled. Refer tosupportedResourceTypes()for the set of resources available.- Returns:
- trueif and only if ResourceManagement is enabled; otherwise- false
- Throws:
- SecurityException- if a SecurityManager is installed and the- RuntimePermission("jdk.management.resource.getResourceContextFactory)is denied
 
 - 
getInstancepublic static ResourceContextFactory getInstance() Returns the factory for ResourceContexts if enabled in the runtime.- Returns:
- the factory for ResourceContexts
- Throws:
- SecurityException- if a SecurityManager is installed and the- RuntimePermission("jdk.management.resource.getResourceContextFactory)is denied
 
 - 
createpublic ResourceContext create(String name) Create a new ResourceContext. A new empty ResourceContext with the specified name is created. The names of ResourceContexts must be unique. Usecloseto dispose of a ResourceContext.- Parameters:
- name- a name for the ResourceContext
- Returns:
- a new ResourceContext
- Throws:
- IllegalArgumentException- if a ResourceContext with the name already exists.
- UnsupportedOperationException- if the number of ResourceContexts exceeds implementation limits
 
 - 
lookuppublic ResourceContext lookup(String name) Returns the ResourceContext given by name.- Parameters:
- name- the name
- Returns:
- the ResourceContext given by name;
          nullif there is no ResourceContext with the name
 
 - 
getThreadContextpublic ResourceContext getThreadContext() Returns the ResourceContext associated with the current thread.- Returns:
- the ResourceContext associated with the current thread;
         the unassigned contextif the thread is not associated with any context
 
 - 
getThreadContextpublic ResourceContext getThreadContext(Thread thread) Returns the ResourceContext associated with the thread.- Parameters:
- thread- the thread to query
- Returns:
- the ResourceContext associated with the current thread;
         the unassigned contextif the thread is not associated with any context
 
 - 
getResourceRequestpublic ResourceRequest getResourceRequest(ResourceType type) Returns the ResourceRequest for the current ResourceContext and ResourceType. If there is no ResourceContext associated with the current thread, theunassigned contextis used.- Parameters:
- type- the ResourceType of the resource making the request
- Returns:
- a ResourceRequest;
     nullif there is no ResourceMeter with the type in the ResourceContext
 
 - 
getUnassignedContextpublic ResourceContext getUnassignedContext() Returns the ResourceContext that is the default when a thread is not associated with a ResourceContext.- Returns:
- the unassigned ResourceContext
 
 - 
getTotalsContextpublic ResourceContext getTotalsContext() Returns a ResourceContext that provides the totals for all ResourceContexts. The meters reflect the sum of all other ResourceContexts plus the final counts of removed ResourceContexts. These meters are read only and are only updated by changes to active ResourceContexts.- Returns:
- the totals ResourceContext
 
 - 
contextspublic Stream<ResourceContext> contexts() Returns a Stream of the existing ResourceContexts.- Returns:
- a Stream of the existing ResourceContexts
 
 - 
supportedResourceTypespublic Set<ResourceType> supportedResourceTypes() Returns a read-only Set of the builtin ResourceTypes available in the current runtime.- Returns:
- a read-only Set of the builtin ResourceTypes available in the current runtime; non-null
 
 
- 
 
-