KML marshal produces zero-length files

你离开我真会死。 提交于 2019-12-06 15:38:04

It could be due to concurrent access. Creating a marshaller is an expensive operation, it takes time and as far as I know marshallers are not threadsafe. I use the jaxb connector in Restlet, coupled with JAK, and that's a good example on how to create marshallers and cache them in a threadsafe way:

/** Use thread identity to preserve safety of access to marshalers. */
private final ThreadLocal<javax.xml.bind.Marshaller> marshaller = new ThreadLocal<javax.xml.bind.Marshaller>() {

See there how the marshaller is created in a synchronized method and then stored in a ThreadLocal variable.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!