簡體   English   中英

批處理中不同流中的常規指令執行

[英]Standing Instruction Execution in a Batch Process in different streams

要回答這個問題,需要一些銀行知識:

說我從帳戶a1-> a2和a2-> a3設置了SI。這只是兩條指令,需要分批處理。 但是我希望這兩個指令將在兩個不同的流中進行處理。

這是不可能的,因為帳戶a2已鎖定在流1中,並且無法在流2中進行處理,直到流1完成處理為止。

解決此問題的方法:要么在一個流中執行所有SI,要么確定指令的依賴性並將這​​些指令相應地放入流中。

還是有其他方法可以解決此問題。

我正在使用Java和Hibernate。

我對您的問題的細節不熟悉,但這聽起來很像管道CPU中的數據危險

在您的情況下,您希望最大程度地利用功能單元(流),而又不會造成數據危害。 也許您可以編寫一個簡單的調度程序來查找下n條指令並將其調度到流中?

/**
 * Keeps track of which stream is scheduled to process each account.
 * If an account is not currently scheduled to be processed, it doesn't appear in the keySet of this map.
 */
Map<Account, Stream> accountsInFlight; // use a synchronized implementation

void schedule(Instruction instruction) {
  // If the input account is in flight somewhere, use that stream
  if (accountsInFlight.containsKey(instruction.getInAccount())) {
    scheduleToStream(instruction, accountsInFlight.get(instruction.getInAccount()));

  // If the output account is in flight somewhere, use that stream
  } else if (accountsInFlight.containsKey(instruction.getOutAccount())) {
    scheduleToStream(instruction, accountsInFlight.get(instruction.getOutAccount()));

  // If neither are in flight, this is a good candidate for parallel execution, 
  // put it in a different stream
  } else {
    Stream stream = // pick a stream (maybe the one with the shortest queue?)
    scheduleToStream(instruction, stream);
  }
}

private void scheduleToStream(Instruction instruction, Stream stream) {
  stream.addToQueue(instruction);
  // Update accountsInFlight
  accountsInFlight.put(instruction.getInAccount(), stream);
  accountsInFlight.put(instruction.getOutAccount(), stream);
}

// Remove accounts from the map when the instruction completes 

請注意,這都是偽造的代碼:沒有經過優化,也沒有正確涵蓋所有情況,但是也許它將為您提供一些入門的思路。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM