顧客 (10000 以上) に価格を送信していますが、以下のコードにはループがあり、計算を待っている顧客の処理に遅延が生じます。
PriceVisibleForCustomer = 価格 + CustomerMargin
価格 - 300 ミリ秒ごとに変更 - 中央ストアから送信され、顧客インスタンスとは関係ありません
CustomerMargn - 顧客の合意/セグメント/管理者の決定などに起因するプラスまたはマイナスの金額。顧客の http セッション中は変更されません。メモリに保持できます。
顧客 - ログイン後にプロセスに参加すると、8 つの製品の価格が急速に変化することがわかります。
多分私はもう少し技術が必要ですか?私はSpring 3/4、Java、Weblogicを持っており、計算された価格を提供するために、このタスク用に別のwebappを作成することさえできました.
Java のスレッドについて考えましたが、10000 人以上の顧客というのはスレッドが多すぎるということでしょうか? このコードを変更するには?アーキテクチャを変更する必要があるかもしれませんが、どうすればよいですか?
/**
* Sends prices to customer. This method is called very often (300ms) as prices are changing in real time.
* Customer should see prices also each 300ms
* @param productId - id of a product that prices will be calculated
* @param productIdToPriceMap
* @param customerIdToMarginMap - this map is changed every time customer logs in or logs out
*/
private static void sendPricesToCustomers(Long productId,
Map<Long, BigDecimal> productIdToPriceMap,
Map<Long, BigDecimal> customerIdToMarginMap) {
//This loop is blocking last customer from receiving price until all other customers wil have theri prices calculated. I could create threads, 10000+ customers will be logged in, I cant create so much threads... can I?
for (Long customerId: customerIdToMarginMap.keySet()){
BigDecimal customerMargin = customerIdToMarginMap.get(customerId);
BigDecimal priceResult = productIdToPriceMap.get(productId).add(customerMargin);
//send priceResult to websocket
}
}