Russell,
Thanks for fixing that. But why didn't you simply declare firstCall as
synchronized, thus:
protected synchronized boolean firstCall() {
boolean ret = firstCall;
firstCall = false;
return ret;
}
which would have the effect of serialising the use of firstCall relative to
the stub instance? I think this is equivalent to the code below, but a bit
simpler and faster.
Glyn
[EMAIL PROTECTED]
rg To: [EMAIL PROTECTED]
cc:
20/02/02 16:49 Subject: cvs commit:
xml-axis/java/src/org/apache/axis/wsdl/toJava
Please respond JavaStubWriter.java
to axis-dev
butek 02/02/20 08:49:53
Modified: java/src/org/apache/axis/client Stub.java
java/src/org/apache/axis/wsdl/toJava JavaStubWriter.java
Log:
Make type mapping registration in the stubs thread safe.
Revision Changes Path
1.5 +16 -0 xml-axis/java/src/org/apache/axis/client/Stub.java
Index: Stub.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/Stub.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Stub.java 20 Feb 2002 13:55:19 -0000 1.4
+++ Stub.java 20 Feb 2002 16:49:53 -0000 1.5
@@ -97,6 +97,22 @@
protected URL cachedEndpoint = null;
protected Integer cachedTimeout = null;
+ // Flag to determine whether this is the first call to register type
mappings.
+ // firstCallLock is used to access this in a thread-safe manner.
+ private boolean firstCall = true;
+ private Object firstCallLock = new Object();
+
+ /**
+ * Is this the first time the type mappings are being registered?
+ */
+ protected boolean firstCall() {
+ synchronized (firstCallLock) {
+ boolean ret = firstCall;
+ firstCall = false;
+ return ret;
+ }
+ } // firstCall
+
/**
* Sets the value for a named property. JAX-RPC 1.0 specification
* specifies a standard set of properties that may be passed
1.33 +1 -3
xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java
Index: JavaStubWriter.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- JavaStubWriter.java 20 Feb 2002 13:55:20 -0000
1.32
+++ JavaStubWriter.java 20 Feb 2002 16:49:53 -0000
1.33
@@ -133,7 +133,6 @@
pw.println(" private java.util.Vector cachedSerQNames =
new java.util.Vector();");
pw.println(" private java.util.Vector cachedSerFactories
= new java.util.Vector();");
pw.println(" private java.util.Vector
cachedDeserFactories = new java.util.Vector();");
- pw.println(" private boolean firstCall = true;");
}
pw.println();
@@ -199,8 +198,7 @@
pw.println(" // The type mapping information is
actually registered in");
pw.println(" // the TypeMappingRegistry of the
service, which");
pw.println(" // is the reason why registration is
only needed for the first call.");
- pw.println(" if (firstCall) {");
- pw.println(" firstCall = false;");
+ pw.println(" if (firstCall()) {");
pw.println(" for (int i = 0; i <
cachedSerFactories.size(); ++i) {");
pw.println(" Class cls = (Class)
cachedSerClasses.get(i);");
pw.println("
javax.xml.rpc.namespace.QName qName =");