newContext() method remains abstract in all implementations and
must be provided by the module to create a new subclass of ReentrantContext
with the appropriate contextual data in it.
Sample Usage:
- create a subclass ReentrantContextImpl to hold the thread state:
static final class ReentrantContextImpl extends ReentrantContext {
// specific cached data
}
- create the appropriate ReentrantContextProvider:
private static final ReentrantContextProvider<ReentrantContextImpl> contextProvider =
new ReentrantContextProviderTL<ReentrantContextImpl>(ReentrantContextProvider.REF_WEAK)
{
@Override
protected ReentrantContextImpl newContext() {
return new ReentrantContextImpl();
}
};
...
void someMethod() {
ReentrantContextImpl ctx = contextProvider.acquire();
try {
// use the context
} finally {
contextProvider.release(ctx);
}
}
ReentrantContext
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| public static final int | |
| public static final int | |
| public static final int | |
| private final int | |
| pack-priv static final byte | |
| pack-priv static final byte | |
| pack-priv static final byte |
| Access | Constructor and Description |
|---|---|
| protected | ReentrantContextProvider(final int
reference type refType)Create a new ReentrantContext provider using the given reference type among hard, soft or weak |
| Modifier and Type | Method and Description |
|---|---|
| public abstract K | |
| protected final Reference | |
| protected abstract K | |
| public abstract void |
| REF_HARD | back to summary |
|---|---|
| public static final int REF_HARD | |
| REF_SOFT | back to summary |
|---|---|
| public static final int REF_SOFT | |
| REF_WEAK | back to summary |
|---|---|
| public static final int REF_WEAK | |
| refType | back to summary |
|---|---|
| private final int refType | |
| USAGE_CLQ | back to summary |
|---|---|
| pack-priv static final byte USAGE_CLQ | |
| USAGE_TL_IN_USE | back to summary |
|---|---|
| pack-priv static final byte USAGE_TL_IN_USE | |
| USAGE_TL_INACTIVE | back to summary |
|---|---|
| pack-priv static final byte USAGE_TL_INACTIVE | |
| ReentrantContextProvider | back to summary |
|---|---|
| protected ReentrantContextProvider(final int refType) Create a new ReentrantContext provider using the given reference type among hard, soft or weak
| |
| acquire | back to summary |
|---|---|
| public abstract K acquire() Give a ReentrantContext instance for the current thread
| |
| getOrCreateReference | back to summary |
|---|---|
protected final Reference
| |
| newContext | back to summary |
|---|---|
| protected abstract K newContext() Create a new ReentrantContext instance
| |
| release | back to summary |
|---|---|
| public abstract void release(K ctx) Restore the given ReentrantContext instance for reuse
| |
| Modifier and Type | Field and Description |
|---|---|
| private final V |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public V |
| strongRef | back to summary |
|---|---|
| private final V strongRef | |
| HardReference | back to summary |
|---|---|
| pack-priv HardReference(final V referent) | |
| get | back to summary |
|---|---|
| public V get() Overrides java. Doc from java. Returns this reference object's referent. If this reference object has
been cleared, either by the program or by the garbage collector, then
this method returns
| |