我在Java併發新的,所以我問什麼是這樣執行操作的最佳方法:我有一個圖像中匹配的子圖像靜態方法如何Java8
。它看起來像:
public static Point match(final BufferedImage subimage, final BufferedImage image)
該方法返回null如果沒有被匹配,否則返回匹配的點。
現在我有一個(大)圖像的40個不同的子圖像,我想要平行匹配。每一秒我都會得到一個新的(大)圖像,我需要一次又一次搜索這40個較小的圖像。我需要每次調用的返回值來匹配我主任務中匹配任務結束時的方法,以便我可以分析它。 此外我需要使用盡可能多的CPU內核來完成此任務。
我該如何做到這一點? 我已經閱讀了很多關於ExecutorService,Task,Runnable等的內容。大多數示例僅顯示如何在paralles中的控制檯上打印某些內容。我真的很困惑我應該在我的方案中採用哪種方式:如何傳遞值以及如何獲得結果?班級的佈局應該如何?此外,我不知道什麼是要走的路,如果我創建40個第二任務(這將需要一些時間來設置任務,對吧?)
代碼將是巨大的解釋吧:)
哇,這正是我一直在尋找!非常感謝你 :) –