pankaj
pankaj

Reputation: 530

Creating many threads in java

I want to simulate human population & for that I want to assign a thread to each individual. (This count should go to billion) Each thread will behave as individual and its end will declare that human dead. I have implemented this using simple thread creation & also by thread pooling. But after some point of time thread allocation just ceases to happen in both the methods. (say after 150000 threads). I know java threads are bound by OS threads in 1:1 ratio & it will pose a problem. What other approach will best simulate this problem?

Upvotes: 2

Views: 179

Answers (1)

gsprs
gsprs

Reputation: 80

You can have a look at the actor model which would be more adapted than threads in your situation.

In particular, akka is open source and well known for its implementation of this pattern : https://doc.akka.io/docs/akka/2.5.3/scala/guide/actors-intro.html

Upvotes: 4

Related Questions