开发者

Performance issue with marshalling/unmarshalling in Glassfish/Unix

开发者 https://www.devze.com 2023-01-28 03:32 出处:网络
I\'ve recently deployed my application on a glassfish installation running on Unix and I\'m having serious performance issues with a section of the code.

I've recently deployed my application on a glassfish installation running on Unix and I'm having serious performance issues with a section of the code. My application has to communicate with another system via XML, and I'm using Jaxb to do the marshalling/unmarshalling of the exchanged messages. Each communication requires one marshal and one unmarshal operation. When I run the application on my computer (Windows XP), the total amount of both operations is less than 2 seconds, but when I run the same application, with the same data, in Unix, the total amount is near 20 seconds, almost 10x more. I've searched thoroughly the server logs, looking for som开发者_如何学编程e clue, but couldn't find nothing useful.

Here is the code for both calls:

    public static <T> String marshal(T transaction) throws JAXBException, IOException {
        JAXBContext jc = JAXBContext.newInstance(transaction.getClass().getPackage().getName());
        Marshaller u = jc.createMarshaller();

        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        u.setProperty("jaxb.encoding", "ISO-8859-1");
        u.marshal(transaction, baos);

        String xml = new String(baos.toByteArray());

        baos.close();

        return xml;
    }

    public static <T> T unmarshal(Class<T> docClass, String xml) throws JAXBException, IOException {
        String packageName = docClass.getPackage().getName();

        InputStream is = new ByteArrayInputStream(xml.getBytes());

        JAXBContext jc = JAXBContext.newInstance(packageName);
        Unmarshaller u = jc.createUnmarshaller();
        Object o = u.unmarshal(is);

        is.close();

        return (T) o;
    }

Can someone help me with this issue?

Kind regards,

Carlos Ferreira


The JAXBContext is threadsafe and can be shared. It does not need to be constantly created. This will improve performance.

0

精彩评论

暂无评论...
验证码 换一张
取 消