-4

我有一個程序,其中有數千個線程。我目前使用一臺主機處理所有需要花費大量時間的線程。如果我想使用多個主機(比如說10個主機,每個主機運行100個不同的線程),我應該如何繼續?使用多個主機運行多線程程序

+0

你在做什麼與所有這些線程,到底是什麼? –

+2

我認爲這個問題太廣泛了。 你有沒有想過一些想法?你能提供一些關於你所做工作性質的更多細節。 – zuckermanori

+0

如果你必須在這樣的規模上進行計算,你可以開始研究這種需求的技術構建:像Hadoop,火花/風暴......但顯然你的問題太廣泛了! – GhostCat

回答

0

在單個JVM上有數千個線程聽起來像一個壞主意 - 你可能花大部分時間進行上下文切換而不是做實際的工作。

要跨多個主機分割您的工作,您不能使用由單個JVM管理的線程。您需要讓每臺主機都暴露一個可以接收部分工作並返回已完成工作結果的API。

一種方法是使用Java RMI(遠程方法調用)來完成此任務,但實際上,您的問題缺乏如此多的細節,以便決定選擇哪種架構。

0
Creating 1000 threads in on JVM is very bad design and need to minimise count. 
High thread count will not give you multi-threading benefit as context switching will be very frequent and will hit performance. 
If you are thinking of dividing in multiple hosts then you need parallel processing system like Hadoop /Spark. 
They internally handles task allocation as well as central system for syncing all hosts on which threads/tasks are running.