java的关闭窗口很慢,Platform.runLater,处理大量任务太慢[关闭]

public class ReadFromQueue

{

order = orderFromQueue;

if(!Repository.ordersIdMap.containsKey(order.orderID))

{

Platform.runLater(new Runnable()

{

@Override public void run()

{

Repository.ordersCollection.add(order);

}

}

});

Repository.ordersIdMap.put(order.orderID, order);

}

所以嗨再次,我提出了另一个问题,导致前一个...很糟糕(抱歉)让我把你放在这个场景中 . 你有一个读者进入一个队列并获得一个订单(让我们说它是一个订单对象,随时可以使用),这个东西工作得如此之快,每秒可以获得大量订单..(确切地说,我得到了40,000个订单不到一分钟)..我有一个单例类的Repository,在这个类中我有一个ordersIdMap(Key String和值Order的ConcurrentHashMap)和一个ObservableList(我的tableView的源代码)的ordersCollection . 我不能添加订单,如果已经存在于集合中,那么在我的 Map 中我将orderId(字符串)保存为密钥,这样如果再次出现相同的订单我必须更新它(否则代码不在这里,但是现在不是重要的) . 问题是调用Platform.runLater绘制UI是给我带来问题的原因 . 为什么?因为如果我去获得另一个订单并且Platform.runLater还没有完成..订单没有在 Map 上创建,所以我的“读者”订单是新的并再次创建它(在这种情况下订单有相同的orderId),所以我一遍又一遍得到相同的订单..我必须说有时候它足够快,订单得到更新..但大多数时间太慢而且订单再次创建 . 我还试图把“Repository.ordersIdMap.put(order.orderID,order);”就在if条件旁边..这样 Map 就会有钥匙,无论怎样......但是仍然不起作用(为什么......?dunno)..另外如果我不使用platform.runlater ..its的工作原理但我得到了很多NullPointersException ..因为我试图更新UI快速..我想..任何答案是有用的!! ..谢谢!抱歉我的英语

编辑:这是整个代码.. execRpt就像一个“小订单”,从我可以创建一个更大的订单..我收到许多execRpt,然后创建订单..如果订单存在更新..如果没有添加它,但它更新失败(有时),只是添加顺序,如果它是一个新的 .

package com.larrainvial.trading.trademonitor.listeners;

import com.larrainvial.trading.emp.Controller;

import com.larrainvial.trading.trademonitor.Repository;

import com.larrainvial.trading.emp.Event;

import com.larrainvial.trading.emp.Listener;

import com.larrainvial.trading.fix44.events.ReceivedExecutionReportEvent;

import com.larrainvial.trading.trademonitor.events.CalculatePositionsEvent;

import com.larrainvial.trading.trademonitor.vo.ExecRptVo;

import com.larrainvial.trading.trademonitor.vo.OrderVo;

import javafx.application.Platform;

import javafx.concurrent.Task;

import quickfix.FieldNotFound;

import quickfix.fix44.ExecutionReport;

public class ReceivedExecutionReportToMonitorListener implements Listener

{

private OrderVo orderVo;

private String ordStatus = "";

private String transactTime = "";

private String text = "";

private int qty = 0;

private int cumQty = 0;

private int lastQty = 0;

private int leavesQty = 0;

private double price = 0;

private double avgPx = 0;

private double lastPx = 0;

@Override

public void eventOccurred(Event event)

{

ExecutionReport executionReport = ((ReceivedExecutionReportEvent)event).message;

try

{

String settlType = "";

String orderID = executionReport.isSetOrderID()? String.valueOf(executionReport.getOrderID().getValue()) : "";

String execID = executionReport.isSetExecID()? String.valueOf(executionReport.getExecID().getValue()) : "";

String execType = executionReport.isSetExecType()? String.valueOf(executionReport.getExecType().getValue()) : "";

String clOrdID = executionReport.isSetClOrdID()? String.valueOf(executionReport.getClOrdID().getValue()) : "";

String clOrdLinkID = executionReport.isSetClOrdLinkID()? String.valueOf(executionReport.getClOrdLinkID().getValue()) : "";

transactTime = executionReport.isSetTransactTime() ? String.valueOf(executionReport.getTransactTime().getValue()) : "";

text = executionReport.isSetText() ? executionReport.getText().getValue().toString() : "";

String tif = executionReport.isSetTimeInForce() ? String.valueOf(executionReport.getTimeInForce().getValue()) : "";

String handlInst = executionReport.isSetHandlInst() ? String.valueOf(executionReport.getHandlInst().getValue()) : "";

String securityExchange = executionReport.isSetSecurityExchange()? String.valueOf(executionReport.getSecurityExchange().getValue()) : "";

String orderType = executionReport.isSetOrdType()? String.valueOf(executionReport.getOrdType().getValue()) : "";

String account = executionReport.isSetAccount() ? String.valueOf(executionReport.getAccount().getValue()) : "None";

ordStatus = String.valueOf(executionReport.getOrdStatus().getValue());

lastPx = executionReport.isSetLastPx()? executionReport.getLastPx().getValue() : 0;

price = executionReport.isSetPrice()? executionReport.getPrice().getValue() : 0;

avgPx = executionReport.isSetAvgPx()? executionReport.getAvgPx().getValue() : 0;

lastQty = executionReport.isSetLastQty()? (int)executionReport.getLastQty().getValue() : 0;

leavesQty = executionReport.isSetLeavesQty()? (int)executionReport.getLeavesQty().getValue() : 0;

cumQty = executionReport.isSetCumQty()? (int)executionReport.getCumQty().getValue() : 0;

qty = executionReport.isSetOrderQty()? (int)executionReport.getOrderQty().getValue() : 0;

ExecRptVo execRpt = new ExecRptVo(orderID,

execID,

execType,

ordStatus,

clOrdID,

clOrdLinkID,

securityExchange,

String.valueOf(executionReport.getSide().getValue()),

qty,

lastQty,

leavesQty,

cumQty,

executionReport.getSymbol().getValue().toString(),

orderType,

price,

lastPx,

avgPx,

tif,

"",

handlInst,

securityExchange,

settlType,

account,

text,

transactTime);

orderVo = new OrderVo(execRpt);

OrderVo orderExist = Repository.ordersIdMap.putIfAbsent(orderID, orderVo);

if(orderExist == null)

{

Platform.runLater(new Runnable()

{

@Override public void run()

{

Repository.ordersCollection.add(orderVo);

}

});

}

else

{

Repository.ordersIdMap.get(orderID).price.set(price);

Repository.ordersIdMap.get(orderID).qty.set(qty);

Repository.ordersIdMap.get(orderID).ordStatus.set(ordStatus);

Repository.ordersIdMap.get(orderID).transactTime.set(transactTime);

Repository.ordersIdMap.get(orderID).text.set(text);

if(avgPx > 0)

Repository.ordersIdMap.get(orderID).avgPx.set(avgPx);

if(cumQty > 0)

Repository.ordersIdMap.get(orderID).cumQty.set(cumQty);

if(lastQty > 0)

Repository.ordersIdMap.get(orderID).lastQty.set(lastQty);

if(lastPx > 0)

Repository.ordersIdMap.get(orderID).lastPx.set(lastPx);

if(leavesQty > 0)

Repository.ordersIdMap.get(orderID).leavesQty.set(leavesQty);

if(ordStatus.equals("8"))

Repository.ordersIdMap.get(orderID).rejected.set("1");

Repository.ordersIdMap.get(orderID).execRpts.add(execRpt);

}

if(execType.equals("1") || execType.equals("2") || execType.equals("F"))

{

CalculatePositionsEvent calculatePositionsEvent = new CalculatePositionsEvent(execRpt);

Controller.dispatchEvent(calculatePositionsEvent);

}

}

catch (FieldNotFound ex)

{

ex.printStackTrace();

}

catch (Exception ex)

{

ex.printStackTrace();

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
java.lang.NullPointerException at com.example.machinepotest.mappertest.tes(mappertest.java:23) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725) at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60) at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131) at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149) at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140) at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84) at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115) at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105) at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37) at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104) at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:214) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:210) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:66) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
05-16

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值