public final class ResourceContextFactory extends Object
ResourceContextFactory
instance and checks if the API is accessible to the caller
new ResourceContext
ResourceContext by name
ResourceContext bound to the current thread
UnassignedContext used for all unbound threads
TotalsContext that tracks totals of all contexts
Stream of the ResourceContexts
getInstance
method checks if there is a SecurityManager
installed and the RuntimePermission("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 unassignedContext
if they are not system threads.
System threads ( with (thread.getThreadGroup().getParent() == null
) are not bound to
the unassignedContext
. The resources used by system threads are not recorded.
Modifier and Type | Method and Description |
---|---|
Stream<ResourceContext> |
contexts()
Returns a Stream of the existing ResourceContexts.
|
ResourceContext |
create(String name)
Create a new ResourceContext.
|
static ResourceContextFactory |
getInstance()
Returns the factory for ResourceContexts if enabled in the runtime.
|
ResourceRequest |
getResourceRequest(ResourceType type)
Returns the ResourceRequest for the current ResourceContext and ResourceType.
|
ResourceContext |
getThreadContext()
Returns the ResourceContext associated with the current thread.
|
ResourceContext |
getThreadContext(Thread thread)
Returns the ResourceContext associated with the thread.
|
ResourceContext |
getTotalsContext()
Returns a ResourceContext that provides the totals for all
ResourceContexts.
|
ResourceContext |
getUnassignedContext()
Returns the ResourceContext that is the default when a thread is not
associated with a ResourceContext.
|
ResourceContext |
lookup(String name)
Returns the ResourceContext given by name.
|
public static ResourceContextFactory getInstance()
SecurityException
- if a SecurityManager is installed and
the RuntimePermission("jdk.management.resource.getResourceContextFactory)
public ResourceContext create(String name)
close
to dispose of a ResourceContext.name
- a name for the ResourceContextIllegalArgumentException
- if a ResourceContext with the name
already exists.UnsupportedOperationException
- if the number of ResourceContexts
exceeds implementation limitspublic ResourceContext lookup(String name)
name
- the namenull
if there is no ResourceContext with the namepublic ResourceContext getThreadContext()
unassigned context
if the thread is not associated with any contextpublic ResourceContext getThreadContext(Thread thread)
thread
- the thread to queryunassigned context
if the thread is not associated with any contextpublic ResourceRequest getResourceRequest(ResourceType type)
unassigned context
is used.type
- the ResourceType of the resource making the requestnull
if there is no ResourceMeter with the type in the ResourceContextpublic ResourceContext getUnassignedContext()
public ResourceContext getTotalsContext()
public Stream<ResourceContext> contexts()
Copyright © 2014, 2015, Oracle and/or its affiliates. All rights reserved.