Skip to content
Eric Bodden edited this page Mar 15, 2015 · 1 revision
public static synchronized Toolkit getDefaultToolkit() {
        if (toolkit == null) {
            try {
                // We disable the JIT during toolkit initialization.  This
                // tends to touch lots of classes that aren't needed again
                // later and therefore JITing is counter-productiive.
                java.lang.Compiler.disable();
                
                java.security.AccessController.doPrivileged(
                        new java.security.PrivilegedAction() {
                    public Object run() {
                        String nm = null;
                        Class cls = null;
                        try {
                            nm = System.getProperty("awt.toolkit", "sun.awt.X11.XToolkit"); //trying get the properties in sting format witch normally should be a class name!!!  "sun.awt.X11.XToolkit" the default one!!
                                cls = Class.forName(nm); // load the class!!
                            } catch (ClassNotFoundException e) {
                                ClassLoader cl = ClassLoader.getSystemClassLoader();
                                if (cl != null) {
                                    try {
                                        cls = cl.loadClass(nm);
                                    } catch (ClassNotFoundException ee) {
                                        throw new AWTError("Toolkit not found: " + nm);
                                    }
                                }
                            }
                            if (cls != null) {
                                toolkit = (Toolkit)cls.newInstance();
                                if (GraphicsEnvironment.isHeadless()) {
                                    toolkit = new HeadlessToolkit(toolkit);
                                }
                            }
                        } catch (InstantiationException e) {
                            throw new AWTError("Could not instantiate Toolkit: " + nm);
                        } catch (IllegalAccessException e) {
                            throw new AWTError("Could not access Toolkit: " + nm);
                        }
                        return null;
                    }
                });
                loadAssistiveTechnologies();
            } finally {
                // Make sure to always re-enable the JIT.
                java.lang.Compiler.enable();
            }
        }
        return toolkit;
    }
Clone this wiki locally