diff -r 29a761eaff0d -r 6cd506508147 src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/XMLStreamWriterFactory.java --- a/src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/XMLStreamWriterFactory.java Fri Feb 14 10:53:55 2014 +0100 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/XMLStreamWriterFactory.java Fri Feb 14 11:13:45 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -62,52 +62,54 @@ /** * Singleton instance. */ - private static volatile @NotNull XMLStreamWriterFactory theInstance; + private static volatile ContextClassloaderLocal writerFactory = + new ContextClassloaderLocal() { + @Override + protected XMLStreamWriterFactory initialValue() { + XMLOutputFactory xof = null; + if (Boolean.getBoolean(XMLStreamWriterFactory.class.getName()+".woodstox")) { + try { + xof = (XMLOutputFactory)Class.forName("com.ctc.wstx.stax.WstxOutputFactory").newInstance(); + } catch (Exception e) { + // Ignore and fallback to default XMLOutputFactory + } + } + if (xof == null) { + xof = XMLOutputFactory.newInstance(); + } - static { - XMLOutputFactory xof = null; - if (Boolean.getBoolean(XMLStreamWriterFactory.class.getName()+".woodstox")) { - try { - xof = (XMLOutputFactory)Class.forName("com.ctc.wstx.stax.WstxOutputFactory").newInstance(); - } catch (Exception e) { - // Ignore and fallback to default XMLOutputFactory + XMLStreamWriterFactory f=null; + + // this system property can be used to disable the pooling altogether, + // in case someone hits an issue with pooling in the production system. + if (!Boolean.getBoolean(XMLStreamWriterFactory.class.getName()+".noPool")) { + try { + Class clazz = xof.createXMLStreamWriter(new StringWriter()).getClass(); + if (clazz.getName().startsWith("com.sun.xml.internal.stream.")) { + f = new Zephyr(xof,clazz); + } + } catch (XMLStreamException ex) { + Logger.getLogger(XMLStreamWriterFactory.class.getName()).log(Level.INFO, null, ex); + } catch (NoSuchMethodException ex) { + Logger.getLogger(XMLStreamWriterFactory.class.getName()).log(Level.INFO, null, ex); + } } + + if(f==null) { + // is this Woodstox? + if(xof.getClass().getName().equals("com.ctc.wstx.stax.WstxOutputFactory")) + f = new NoLock(xof); + } + if (f == null) + f = new Default(xof); + + if (LOGGER.isLoggable(Level.FINE)) { + LOGGER.log(Level.FINE, "XMLStreamWriterFactory instance is = {0}", f); + } + return f; } - if (xof == null) { - xof = XMLOutputFactory.newInstance(); - } - - XMLStreamWriterFactory f=null; - - // this system property can be used to disable the pooling altogether, - // in case someone hits an issue with pooling in the production system. - if (!Boolean.getBoolean(XMLStreamWriterFactory.class.getName()+".noPool")) { - try { - Class clazz = xof.createXMLStreamWriter(new StringWriter()).getClass(); - if (clazz.getName().startsWith("com.sun.xml.internal.stream.")) { - f = new Zephyr(xof,clazz); - } - } catch (XMLStreamException ex) { - Logger.getLogger(XMLStreamWriterFactory.class.getName()).log(Level.INFO, null, ex); - } catch (NoSuchMethodException ex) { - Logger.getLogger(XMLStreamWriterFactory.class.getName()).log(Level.INFO, null, ex); - } - } - - if(f==null) { - // is this Woodstox? - if(xof.getClass().getName().equals("com.ctc.wstx.stax.WstxOutputFactory")) - f = new NoLock(xof); - } - if (f == null) - f = new Default(xof); - - theInstance = f; - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "XMLStreamWriterFactory instance is = {0}", f); - } - } + }; /** * See {@link #create(OutputStream)} for the contract. @@ -170,7 +172,7 @@ * Gets the singleton instance. */ public static @NotNull XMLStreamWriterFactory get() { - return theInstance; + return writerFactory.get(); } /** @@ -183,7 +185,7 @@ @SuppressWarnings({"null", "ConstantConditions"}) public static void set(@NotNull XMLStreamWriterFactory f) { if(f==null) throw new IllegalArgumentException(); - theInstance = f; + writerFactory.set(f); } /**