Problem when sending and receiving data

1

I am trying to perform two processes using bean, my problem is that I can not find the way these processes are carried out continuously. The first process is to send an object and the second process is the response of it.

@Component
public class Proceso implements InitializingBean{
private static final String XML_SCHEMA_LOCATION = "/proceso/model/schema/proceso.xsd";
private Envio envio;
private Respuesta respuesta;

public void Proceso_envio(Proceso proceso, OutputStream outputstream) throws JAXBException{
  envio.marshal(proceso, outputstream);}

public void Proceso_respuesta(InputStream inputstream) throws JAXBException, FileNotFoundException{
Object obj = unmarshaller.unmarshal(inputStream);
return (Proceso_respuesta) obj;}

@Override
public void afterPropertiesSet() throws Exception{
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(getClass().getResource(XML_SCHEMA_LOCATION));
JAXBContext jc = JAXBContext.newInstance(Envio.class, Respuesta.class);

this.marshaller = jc.createMarshaller();
this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
this.marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.displayName());
this.marshaller.setSchema(schema);

this.unmarshaller = jc.createUnmarshaller();

this.unmarshaller.setSchema(schema);
 }

I imagine that with the code my question becomes clearer.

    
asked by mantamusica 06.06.2017 в 12:46
source

1 answer

1

Try adding the keyword synchronized to the methods.

More than once something similar to this has happened to me and I did not do the processes because the method that it receives, tries to read something that has not arrived

By adding that keyword the methods are synchronized and while one is doing one thing the other will not be called until the other has finished

I leave you the javadoc for more info: link

    
answered by 06.06.2017 / 12:57
source