|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.Thread
com.denova.ui.SwingCheckerThread
public class SwingCheckerThread
Replacement for Thread that checks many Swing methods for thread safety. It writes possible Swing thread errors to the log file {value #SwingCheckerThreadLogName}. The log file must exist before your program starts.
SwingCheckerThread checks Swing code at runtime. If can only check code that runs. That means you can get different results at different times and on different platforms. User choices, data differences, system configuration and races can all change the path your code takes at runtime. JVMs implement Swing and threading differently.
SwingCheckerThread only checks swing methods that use the RepaintManager. It will not check Swing methods that do not use the RepaintManager, such as methods that read values.
To make a Swing method call thread safe, use SwingUtilities.invokeLater(), or SwingUtilities.invokeAndWait(), or SwingWorker.
Warning: This check slows down your application. To disable Swing thread checking, delete the log file.
When you create a thread that may call into Swing, instead of
extends Thread
use
extends SwingCheckerThread
and instead of
new Thread(...
use
new SwingCheckerThread(...
If you are already in a thread and you want to check it, use
SwingCheckerThread.startChecking();
The javadocs say some Swing methods are thread safe. Which ones actually are thread safe have changed over time. It is safer to assume none are thread safe.
Private class Checker derived from CheckingRepaintManager in Easily Find Swing Threading Issues, where the author says the code has an "unrestrictive license". Last modified: 2008-05-22
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.lang.Thread |
|---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
| Field Summary | |
|---|---|
static java.lang.String |
SwingCheckerThreadLogName
|
| Fields inherited from class java.lang.Thread |
|---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
|---|---|
SwingCheckerThread()
SwingCheckerThread constructor. |
|
SwingCheckerThread(java.lang.Runnable runnableClass)
SwingCheckerThread constructor. |
|
| Method Summary | |
|---|---|
static Log |
getLog()
|
static boolean |
isEnabled()
|
static void |
setEnabled(boolean newEnabled)
|
static void |
startChecking()
Starts checking swing calls for the current thread group. |
| Methods inherited from class java.lang.Thread |
|---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static java.lang.String SwingCheckerThreadLogName
| Constructor Detail |
|---|
public SwingCheckerThread()
public SwingCheckerThread(java.lang.Runnable runnableClass)
runnableClass - class that implements Runnable| Method Detail |
|---|
public static void startChecking()
public static boolean isEnabled()
public static void setEnabled(boolean newEnabled)
public static Log getLog()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||