我有一个使用单例bean的restfull应用程序。这个bean由windows10上的glassfish5.1容器管理。当我关闭服务器时,bean的savedata()被调用,它假设使用jaxb将应用程序数据保存到一个xml文件中。查看日志,该方法由容器调用,但没有完全执行,因此没有创建xml数据文件。
@Singleton
@Startup
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
//This bean will be managed by the container automatically since it is a singleton. The container calls
//the method that has a @PostConstruct annotation. This is ideal to perform initial data load into the
// the data store
public class DataLoaderSessionBean {
@EJB
private RequestSessionBean request;
private final static String logPath = "C:\\Logs\\log.txt";
private final static String dataPath = "c:\\Logs\\Parts.xml";
private final static Logger logger = LoggerUtil.getLogger(DataLoaderSessionBean.class.getName(),
logPath);
@PostConstruct
public void createData() {
}
@PreDestroy
public void saveData() {
logger.entering(DataLoaderSessionBean.class.getName(), "saveData()");
try {
List<Part> parts = request.getAllParts();
if (parts != null) {
logger.log(Level.INFO, "The size of list to save {0}", new Object[]{parts.size()});
parts.stream()
.forEach(e -> logger.log(Level.INFO, "saving part {0} {1}",
new Object[]{e.getName(), e.getNumber()}));
PartWrapper warpper = new PartWrapper();
warpper.setParts(parts);
logger.log(Level.INFO,"Marshaller created");
JAXBContext context = JAXBContext
.newInstance(PartWrapper.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
// Marshalling and saving XML to the file.
m.marshal(warpper, new File(dataPath));
logger.log(Level.INFO, "Finished saveing data to {0}", dataPath);
} else {
logger.log(Level.INFO, "Warning: NO PARTS TO SAVE!!!!");
}
} catch (JAXBException e) {
logger.log(Level.SEVERE,
"JAXBException occured while saving data to XML: message {0} class {1}",
new Object[]{e.getMessage(),e.getCause()});
StackTraceElement[] s = e.getStackTrace();
for(StackTraceElement ste: s){
logger.log(Level.SEVERE,"Printing stacktrace element {0}",ste.toString());
}
}
logger.exiting(DataLoaderSessionBean.class.getName(), "saveData()");
}
}
查看日志,它显示方法savedata()一直执行到partwrapper类被示例化的那一行,然后方法执行以某种方式结束,并且应用程序和容器都没有抛出异常。以下是日志中的一个片段:
[2020-12-04T18:55:01.941+0330] [glassfish 5.0] [WARNING] [] [org.eclipse.persistence.session./file:/C:/Users/mrr/Documents/NetBeansProjects/webdevelopment/RESTfulService/FromPattern/mavenlistservicedb/target/mavenlistservicememory-1/WEB-INF/classes/_listserviceDB.server] [tid: _ThreadID=221 _ThreadName=RunLevelControllerThread-1607095500635] [timeMillis: 1607095501941] [levelValue: 900] [[
Failed to find MBean Server: null or empty List returned from MBeanServerFactory.findMBeanServer(null)]]
[2020-12-04T18:55:02.052+0330] [glassfish 5.0] [INFO] [] [org.me.mavenlistservicedb.ejb.DataLoaderSessionBean] [tid: _ThreadID=221 _ThreadName=RunLevelControllerThread-1607095500635] [timeMillis: 1607095502052] [levelValue: 800] [[
The size of list to save 1]]
[2020-12-04T18:55:02.053+0330] [glassfish 5.0] [SEVERE] [] [] [tid: _ThreadID=221 _ThreadName=Thread-9] [timeMillis: 1607095502053] [levelValue: 1000] [[
Dec 04, 2020 6:55:02 PM org.me.mavenlistservicedb.ejb.DataLoaderSessionBean saveData
INFO: The size of list to save 1
]]
[2020-12-04T18:55:02.056+0330] [glassfish 5.0] [INFO] [] [org.me.mavenlistservicedb.ejb.DataLoaderSessionBean] [tid: _ThreadID=221 _ThreadName=RunLevelControllerThread-1607095500635] [timeMillis: 1607095502056] [levelValue: 800] [[
saving part Clutch Pressure Plate PP23864CL]]
[2020-12-04T18:55:02.057+0330] [glassfish 5.0] [SEVERE] [] [] [tid: _ThreadID=221 _ThreadName=Thread-9] [timeMillis: 1607095502057] [levelValue: 1000] [[
Dec 04, 2020 6:55:02 PM org.me.mavenlistservicedb.ejb.DataLoaderSessionBean lambda$saveData$1
INFO: saving part Clutch Pressure Plate PP23864CL
]]
[2020-12-04T18:55:02.157+0330] [glassfish 5.0] [INFO] [] [org.eclipse.persistence.session./file:/C:/Users/mrr/Document/NetBeansProjects/webdevelopment/RESTfulService/FromPattern/mavenlistservicedb/target/mavenlistservicememory-1/WEB-INF/classes/_listserviceDB.connection] [tid: _ThreadID=221 _ThreadName=RunLevelControllerThread-1607095500635] [timeMillis: 1607095502157] [levelValue: 800] [[
/file:/C:/Users/mrr/Documents/NetBeansProjects/webdevelopment/RESTfulService/FromPattern/mavenlistservicedb/target/mavenlistservicememory-1/WEB-INF/classes/_listserviceDB logout successful]]
[2020-12-04T18:55:02.219+0330] [glassfish 5.0] [SEVERE] [] [javax.enterprise.web.util] [tid: _ThreadID=221 _ThreadName=RunLevelControllerThread-1607095500635] [timeMillis: 1607095502219] [levelValue: 1000] [[
The web application [] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4c3fefac]) and a value of type [org.glassfish.admingui.theme.AdminguiThemeContext] (value [org.glassfish.admingui.theme.AdminguiThemeContext@22bde63f]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.]]
你知道吗?
谢谢
暂无答案!
目前还没有任何答案,快来回答吧!