- js
$(function(){
initTodoInfo(true);
})
//Get the scheduling command information and assign it to the prompt button findDcmdSize
function initDcmdInfo(showWindow){
var url = 'nnmis/view/dcmd/findDcmdSizeDCMD.tg';
$.post(url, {}, function (data) {
if(data != ""){
//From JSON data, parse quantity and new alarms
var response = eval("("+ data +")");
var totalCount = response[0].TOTALCNT;
//Update the displayed value of the quantity
$("#dcmd_info_label").html("Command["+totalCount+"]");
}
});
}
//Number of regular updates
var getRealData = self.setInterval("initTodoInfo(true);", 60000);
2. action
@Autowired
private DcmdData ddata;
/**
* Returns the number of unprocessed items for the day
*/
public void findDcmdSize() {
String dataGridStr = "";
// List<Map> dcmdlist = dcmdService.findDcmdListNumByCondtion(dcmd);
List<Map> dcmdlist = ddata.getDcmdList();
if (dcmdlist.size() == 0) {
dcmdlist = dcmdService.findDcmdListNumByCondtion(dcmd);
}
dataGridStr = super.autoDMapLst2DgJson(dcmdlist);
returnJson(dataGridStr, response);
}
3. to do data cache class
package com.casco.csmis.dcmd.data;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import com.casco.csmis.dcmd.service.IDcmdInfoService;
import com.casco.csmis.dcmd.vo.DcmdInfo;
/**
* <b> To-Do Data Cache Class<b>
* <p>
* Created by 60847
*/
@Repository(value = "dcmdData")
@Service
public class DcmdData {
@Autowired
private IDcmdInfoService dcmdService;
private static List<Map> dcmdList = new ArrayList<Map>();
private DcmdInfo dcmd;
public static List<Map> getDcmdList() {
return dcmdList;
}
public static void setDcmdList(List<Map> dcmdList) {
DcmdData.dcmdList = dcmdList;
}
public DcmdData() {
}
public DcmdData(IDcmdInfoService dcmdService) {
this.dcmdService = dcmdService;
}
/**
* Initialization
*/
public void init() {
try {
dcmdList = dcmdService.findDcmdListNumByCondtion(dcmd);
} catch (Exception e) {
e.printStackTrace();
}
}
}
4. Call the thread to start the thread when the server starts
/**
* @Title: MemoryListener.java
* @Package com.casco.csmis.listener
* @Description:
* @author ligangying [email protected]
* @date 2013-10-2 AM 9:56:33
* @version V1.0
*/
package com.casco.csmis.permissions.listener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.casco.csm.casco.core.tools.util.ReadProperty;
import com.casco.csmis.dcmd.data.DcmdData;
/**
* @ClassName: MemoryListener
* @Description: Initialize global parameters and system dictionary
* @author sunct [email protected]
* @date 2013-10-6 下午3:03:16
*/
public class MemoryListener implements ServletContextListener {
private DcmdData dcmdData;
Log logger = LogFactory.getLog(MemoryListener.class);
@Override
public void contextDestroyed(ServletContextEvent arg0) {
logger.debug("tomcat Done");
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(arg0.getServletContext());
this.setDcmdData((DcmdData) ctx.getBean("dcmdData"));
logger.debug("tomcat start running");
Thread dcmdThread = new Thread(new DcmdThread(this.getDcmdData()));
dcmdThread.start();
}
public DcmdData getDcmdData() {
return dcmdData;
}
public void setDcmdData(DcmdData dcmdData) {
this.dcmdData = dcmdData;
}
}
5. Thread call cache class
package com.casco.csmis.dcmd.util;
import com.casco.csmis.dcmd.data.DcmdData;
/*
* Receiving server responsible for receiving data sent from C++
*/
public class DcmdThread implements Runnable {
private DcmdData dcmdData;
public DcmdData getDcmdData() {
return dcmdData;
}
public void setDcmdData(DcmdData dcmdData) {
this.dcmdData = dcmdData;
}
public DcmdThread(DcmdData dcmdData) {
this.setDcmdData(dcmdData);
}
@Override
public void run() {
while (true) {
// Reading the datas
try {
dcmdData.init();
Thread.sleep(30000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
6 server class configuration in web.xml
<listener>
<listener-class>com.casco.csmis.permissions.listener.MemoryListener</listener-class>
</listener>
Read More:
- Implementation of retrial mechanism in Java
- Java uses single thread pool to realize multi thread sequential execution (non alternating, non synchronous)
- Three ways of thread sequence alternate execution in Java lock free programming
- Java uses class array to report error Exception in thread “main” java.lang.NullPointerException solution
- [Solved] Exception in thread “main“ java.lang.NoSuchFieldError: level
- [Solved] qrcode-error: Exception in thread “main” java.lang.NoClassDefFoundError…
- Java callback function implementation case
- [Solved] Docker Elasticsearch8.4.0 Error: Exception in thread “main” java.nio.file.FileSystemException
- Java implementation of inputsteam to Base64
- Jmeter Error: ERROR o.a.j.JMeter: Uncaught exception in thread Thread[AWT-EventQueue-0,6,main]
- [Solved] Hadoop Error: Exception in thread “main“ java.io.IOException: Error opening job jar: /usr/local/hadoop-2.
- Java: How to use itext to export PDF text absolute positioning (implementation method)
- Mybatis query error: Exception in thread “main” org.apache.ibatis.exceptions.PersistenceException…
- [Solved] Error: A JNI error has occurred, please check your installation and try again Exception in thread
- [Solved] Jxls error: Cannot load XLS transformer. Please make sure a Transformer implementation is in classpath
- [Solved] java Internal error in the mapping processor java.lang.NullPointerException
- [Solved] java Internal error in the mapping processor java.lang.NullPointerException
- [Solved] IDEA springboot Startup Error: java.lang.UnsatisfiedLinkError: no tcnative-1 in java.library.path
- [Solved] java: Internal error in the mapping processor: java.lang.NullPointerException
- C language: Implementation of dynamic array initialization, insertion, traversal, deletion and destruction