RestrictThreadCreation.java | Class | Permits unit tests to limit creation of threads.
Unexpected thread creation can make tests fail randomly, which makes debugging difficult.
Start off calling
RestrictThreadCreation.permitStandard and
RestrictThreadCreation.forbidNewThreads .
To determine which methods to permit, just try running the test;
if you see any
SecurityException s which look like harmless thread creation
activities, just copy the appropriate part of the stack trace and pass to
RestrictThreadCreation.permit .
Use non-strict mode for
RestrictThreadCreation.forbidNewThreads if you suspect some code
might be catching and not reporting
SecurityException s; or you may prefer
to simply use non-strict mode while developing the test and then switch to strict
mode once it begins passing.
Place calls to this class early in your test's initialization, e.g. |