猿问

Exception in thread "pool-6-thread-46" java.lang.NullPointerException怎么解决?

Exception in thread "pool-6-thread-1" java.lang.NullPointerException

at com.pats.client.cache.VwapBookCache.removeOldVwapBook(VwapBookCache.java:46)

at com.pats.client.publish.workingpool.ContentVwapThread.run(ContentVwapThread.java:54)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

代码:

public void run() {

        try {

            server = new Server(config.getItemInt("SYSTEM", "PORT", 8081));

            HandlerList handlerList = new HandlerList();

            ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

            //context.setContextPath("/pats");

            xmlContext = new XmlWebApplicationContext();


            // load spring configration xml

            String springXML = "file:"+SYSTEM_PATH + File.separator + "app_all.xml";

            xmlContext.setConfigLocations(springXML);

            context.addEventListener(new ContextLoaderListener(xmlContext));

            context.addServlet(new ServletHolder(new DispatcherServlet(xmlContext)), "/*");


            // druid web configure start

            context.addServlet(new ServletHolder(new StatViewServlet()), "/druid/*");

            FilterHolder filter = new FilterHolder(new WebStatFilter());

            FilterHolder myfilter = new FilterHolder(new com.pats.client.cors.CORSFilter());

            filter.setInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");

            filter.setInitParameter("profileEnable", "true");

            filter.setInitParameter("principalCookieName", "USER_COOKIE");

            filter.setInitParameter("principalSessionName", "USER_SESSION");

            context.addFilter(filter, "/*", EnumSet.of(DispatcherType.REQUEST));

            context.addFilter(myfilter, "/*", EnumSet.of(DispatcherType.REQUEST));

            

            // druid web configure end


            // websocket configure

            context.addServlet(new ServletHolder(new FxpocServlet()), "/fxpoc");

            context.addServlet(new ServletHolder(new CMBCServlet()), "/cmbcsocket");

         //   context.addServlet(new ServletHolder(new FxpocServlet()), "/fxpoc");

            context.addServlet(new ServletHolder(new BoardServlet()), "/boardsocket");

            // context.addServlet(new ServletHolder(new MsgListServlet()), "/msglist");

            context.addServlet(new ServletHolder(new PositionServlet()), "/positionsocket");


            // Website configure

            Properties properties = new Properties(System.getProperties());

            String websitePath = SYSTEM_PATH + properties.getProperty("file.separator") + "website";

            logger.info("Website path is " + websitePath);

            ResourceHandler handler = new ResourceHandler();

            handler.setDirectoriesListed(true);

            handler.setResourceBase(websitePath);

            handler.setMinMemoryMappedContentLength(-1);


            handlerList.addHandler(handler);

            handlerList.addHandler(context);

            handlerList.addHandler(new DefaultHandler());

            server.setHandler(handlerList);

            server.start();


            // ===== ACTIVEMQ start ========

            // ActiveMQGetSpotProductDataMsg.getMsg().startread();

            // ===== ACTIVEMQ end ========


            // init codeSet tenor


            initCache();

            startMQReaders();


            logger.info("pats-publish is ok !");

            server.join();

        } catch (Exception e) {

            logger.error("Sorry, an exception has occurred.", e);

        }

    }

public class ContentVwapThread extends Thread {

private VwapBook inputMsg = null;

public ContentVwapThread(VwapBook msg) {

this.inputMsg = msg;

}


@Override

public void run() {

VwapBook vwapBook = inputMsg;

Iterator<Map.Entry<Session, String>> sessionObjects = null;

ConstructBoardMsg boardMsg = new ConstructBoardMsg(vwapBook);

boardMsg.decodeVwapPrice();

Map<String, Object> returnData = boardMsg.getReturnData();

sessionObjects = BoardSocket.sessionlist.entrySet().iterator();

while (sessionObjects.hasNext()) {

Map.Entry<Session, String> entry = sessionObjects.next();

Session session = entry.getKey();

String userID = entry.getValue();

ConcurrentHashMap<String, Set<String>> selectedVolumeMap = UserCache.selectedVolumeMap.get(userID);

if (selectedVolumeMap != null) {

// 获取用户定义的交易量

Set<String> setOfSelectedVolumes = selectedVolumeMap.get(vwapBook.getSymbol());

if (setOfSelectedVolumes != null) {

for (String volume : setOfSelectedVolumes) {

double currentVolume = Double.parseDouble(ClientUtil.volumeShortToFull(volume));

if (vwapBook.getTargetAskVolume().getRawVolume() == currentVolume) {

SendMsgUtil.send(session, returnData);

VwapBookCache.vwapBookMap.put(vwapBook.getVwapBookID(), vwapBook);

VwapBookCache.removeOldVwapBook();

}

}

}

}

}

}

}

public class VwapBookCache {

private static VwapBookCache instance;

private static byte[] lock = new byte[0];

private static int maxTimetoKeepMills = 100;

public static ConcurrentHashMap<String,VwapBook> vwapBookMap = new ConcurrentHashMap<>();

private VwapBookCache(){

}

public static VwapBookCache getInstance() {

synchronized (lock) {

if (instance == null) {

instance = new VwapBookCache();

}

}

return instance;

}

public ConcurrentHashMap<String, VwapBook> getVwapBookMap() {

return vwapBookMap;

}


public static void removeOldVwapBook() {

Iterator<String> iterator = VwapBookCache.vwapBookMap.keySet().iterator();

Date now = new Date();

Long nowTime = new Long(now.getTime() / 1000);

while (iterator.hasNext()) {

String key = iterator.next();

String priceTimeS = VwapBookCache.vwapBookMap.get(key).getCreateTime();

Long priceTime = Long.parseLong(priceTimeS);

if (nowTime - priceTime > maxTimetoKeepMills) {

VwapBookCache.vwapBookMap.remove(key);

}

}

}


}


慕粉仔仔
浏览 2680回答 1
1回答

谦谦佳人

从日志上看 应该是VwapBookCache 类的第46行出现空指针异常,你可以将46行所有用到的变量都打印出来 或者直接在debug模式下查看其值
随时随地看视频慕课网APP

相关分类

Java
我要回答