Incorrect output under "load" (multiple concurrent calling threads) Is this code thread- [message #417624] |
Tue, 18 March 2008 19:36 |
Eclipse User |
|
|
|
Originally posted by: GaryRMartin.insightbb.com
Only under load (multiple concurrent calling threads) the following code
intermittently
gives incorrect results. Is there "obviously" something not thread
safe-with the following code?
package com.ibm.fcbst.common.domain.converter;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl;
import org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl;
import com.ibm.fcbst.common.domain.sdo.DocumentRoot;
import com.ibm.fcbst.common.domain.sdo.impl.FcbstPackageImpl;
import com.ibm.fcbst.common.domain.sdo.util.FcbstResourceFactoryImp l;
public class SDO2XML {
public final static String convertOld(DocumentRoot documentRoot)
throws IOException {
ResourceSet resourceSet = new ResourceSetImpl();
java.util.Map rr = Collections.synchronizedMap(resourceSet
.getResourceFactoryRegistry().getExtensionToFactoryMap());
rr.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
new FcbstResourceFactoryImpl());
org.eclipse.emf.ecore.EPackage.Registry r = resourceSet
.getPackageRegistry();
r.put(FcbstPackageImpl.eNS_URI, FcbstPackageImpl.eINSTANCE);
XMLResource resource = (XMLResource) resourceSet.createResource(URI
.createURI(FcbstPackageImpl.eNS_URI));
resource.getContents().add(documentRoot);
resource.setEncoding("UTF-8");
StringWriter stringWriter = new StringWriter();
resource.save(new URIConverter.WriteableOutputStream(stringWriter,
resource.getEncoding()), null);
stringWriter.close();
String st = stringWriter.toString();
return st;
}
}
Correct returned String:
<?xml version="1.0" encoding="UTF-8"?>
<fcbst:user xmlns:fcbst="http://fcbst.ibm.com">
<msgHeader>
<princ id="0" type="Usr"/>
</msgHeader>
<payLoad>
<user lng="en_US" title="user15031" type="Usr">
<avatar avatarId="Ava"/>
<name>user15031</name>
<email>test15031@mail.ru</email>
<pass>passs</pass>
<city>New Holland</city>
<st>NY</st>
<ctry>Aruba</ctry>
<isPub>false</isPub>
<recUpd>false</recUpd>
<enblLbl>A</enblLbl>
<opacMin>40</opacMin>
<opacMax>80</opacMax>
<fadeTm>5</fadeTm>
</user>
</payLoad>
</fcbst:user>
Incorrect returned String:
<?xml version="1.0" encoding="UTF-8"?>
<fcbst xmlns:fcbst="http://fcbst.ibm.com"><fcbst:user>
<msgHeader>
<princ id="0" type="Usr"/>
</msgHeader>
<payLoad>
<user lng="en_US" title="user15031" type="Usr">
<avatar avatarId="Ava"/>
<name>user15031</name>
<email>test15031@mail.ru</email>
<pass>passs</pass>
<city>New Holland</city>
<st>NY</st>
<ctry>Aruba</ctry>
<isPub>false</isPub>
<recUpd>false</recUpd>
<enblLbl>A</enblLbl>
<opacMin>40</opacMin>
<opacMax>80</opacMax>
<fadeTm>5</fadeTm>
</user>
</payLoad>
</fcbst:user></fcbst>
|
|
|
Re: Incorrect output under "load" (multiple concurrent calling threads) Is this code threa [message #417625 is a reply to message #417624] |
Tue, 18 March 2008 20:38 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Gary,
No, I don't see anything obviously wrong. In fact, I can't imagine what
you see here being caused by thread safety. It seems to me you'd only
get the second serialization if the model structure itself is
different.. If you added a print statement like
System.err.println(documentRoot.eContents().get(0)), I wonder if the
root object is somehow different in each case...
Gary Martin wrote:
> Only under load (multiple concurrent calling threads) the following code
> intermittently
> gives incorrect results. Is there "obviously" something not thread
> safe-with the following code?
>
>
> package com.ibm.fcbst.common.domain.converter;
>
> import java.io.IOException;
> import java.io.StringWriter;
> import java.util.Collections;
> import java.util.HashMap;
> import java.util.Map;
> import java.util.logging.Logger;
>
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
> import org.eclipse.emf.ecore.resource.URIConverter;
> import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
> import org.eclipse.emf.ecore.xmi.XMLResource;
> import org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl;
> import org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl;
>
> import com.ibm.fcbst.common.domain.sdo.DocumentRoot;
> import com.ibm.fcbst.common.domain.sdo.impl.FcbstPackageImpl;
> import com.ibm.fcbst.common.domain.sdo.util.FcbstResourceFactoryImp l;
>
> public class SDO2XML {
>
> public final static String convertOld(DocumentRoot documentRoot)
> throws IOException {
>
> ResourceSet resourceSet = new ResourceSetImpl();
>
> java.util.Map rr = Collections.synchronizedMap(resourceSet
> .getResourceFactoryRegistry().getExtensionToFactoryMap());
>
> rr.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
> new FcbstResourceFactoryImpl());
>
> org.eclipse.emf.ecore.EPackage.Registry r = resourceSet
> .getPackageRegistry();
>
> r.put(FcbstPackageImpl.eNS_URI, FcbstPackageImpl.eINSTANCE);
>
> XMLResource resource = (XMLResource) resourceSet.createResource(URI
> .createURI(FcbstPackageImpl.eNS_URI));
> resource.getContents().add(documentRoot);
> resource.setEncoding("UTF-8");
>
> StringWriter stringWriter = new StringWriter();
> resource.save(new URIConverter.WriteableOutputStream(stringWriter,
> resource.getEncoding()), null);
> stringWriter.close();
> String st = stringWriter.toString();
>
> return st;
> }
> }
>
> Correct returned String:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <fcbst:user xmlns:fcbst="http://fcbst.ibm.com">
> <msgHeader>
> <princ id="0" type="Usr"/>
> </msgHeader>
> <payLoad>
> <user lng="en_US" title="user15031" type="Usr">
> <avatar avatarId="Ava"/>
> <name>user15031</name>
> <email>test15031@mail.ru</email>
> <pass>passs</pass>
> <city>New Holland</city>
> <st>NY</st>
> <ctry>Aruba</ctry>
> <isPub>false</isPub>
> <recUpd>false</recUpd>
> <enblLbl>A</enblLbl>
> <opacMin>40</opacMin>
> <opacMax>80</opacMax>
> <fadeTm>5</fadeTm>
> </user>
> </payLoad>
> </fcbst:user>
>
>
> Incorrect returned String:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <fcbst xmlns:fcbst="http://fcbst.ibm.com"><fcbst:user>
> <msgHeader>
> <princ id="0" type="Usr"/>
> </msgHeader>
> <payLoad>
> <user lng="en_US" title="user15031" type="Usr">
> <avatar avatarId="Ava"/>
> <name>user15031</name>
> <email>test15031@mail.ru</email>
> <pass>passs</pass>
> <city>New Holland</city>
> <st>NY</st>
> <ctry>Aruba</ctry>
> <isPub>false</isPub>
> <recUpd>false</recUpd>
> <enblLbl>A</enblLbl>
> <opacMin>40</opacMin>
> <opacMax>80</opacMax>
> <fadeTm>5</fadeTm>
> </user>
> </payLoad>
> </fcbst:user></fcbst>
>
>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03334 seconds