public class Apartment extends Object
| Constructor and Description |
|---|
Apartment() |
| Modifier and Type | Method and Description |
|---|---|
static Object |
inApartment(Supplier closure)
Call the closure in the context of the current apartment model, defaulting
to MTA (the more universally applicable threading model)if no apartment
model has been defined.
|
static void |
initMTA()
Initialize thread as an MTA (for compatibility with Java).
|
static void |
initSTA()
Initialize thread as an STA (for compatibility with Java).
|
static void |
releaseMTA()
Releases the MTA thread (for compatibility with Java).
|
static void |
releaseSTA()
Releases the STA thread (for compatibility with Java).
|
static Object |
withMTA(Supplier closure)
Call the closure in the context of an MTA.
|
static Object |
withSTA(Supplier closure)
Call the closure in the context of an STA.
|
public static Object inApartment(Supplier closure)
This is the preferred way to wrap your code in an apartment context, since
it works with either STA or MTA models. If you need to specifically use
MTA or STA models, use the withMTA(java.util.function.Supplier) or withSTA(java.util.function.Supplier) methods.
Note that MTA and STA methods do not nest and may not be used together
in the same thread.
closure - The closure to call.withMTA(java.util.function.Supplier),
withSTA(java.util.function.Supplier)public static Object withSTA(Supplier closure)
withSTA() calls, but not withMTA(java.util.function.Supplier). The use of withSTA()
is discouraged, since it appears to cause JVM crashes in testing.closure - The closure to call.inApartment(java.util.function.Supplier)public static void initSTA()
public static void releaseSTA()
initSTA().public static Object withMTA(Supplier closure)
withMTA() calls, but not withSTA(java.util.function.Supplier).closure - The closure to call.inApartment(java.util.function.Supplier)public static void initMTA()
public static void releaseMTA()
initMTA().Copyright © 2020. All rights reserved.