d. dutch
d. dutch

Reputation: 11

(Tomcat) Web service : OutOfMemoryError: unable to create new native thread

I am creating a web service that creates a huge amount of small java timer threads over (10k). I can only seem to create 2k timer threads before I get the OutOfMemoryError: unable to create new native thread. How do i solve this? I am using a macbook pro to run my Tomcat server on. I'v configured the ulimit (-u) max user processes to double what it used to be but I still get the same problem. What are my options, if any, to make this doable?

Upvotes: 0

Views: 366

Answers (1)

Olaf Kock
Olaf Kock

Reputation: 48067

It's often a bad idea for web applications to start their own (few) threads, let alone 10K threads - and then "as timers"? Seriously? Don't go there.

What can you do?

  • Don't rely on the ability to create those threads.
  • Change your architecture! Use a scheduler library that has solved this problem already (e.g. Quartz or others).
  • If you don't want to use an external library (why wouldn't you?): Implement a single timer thread that executes the scheduled operations when they're due. Do not use a new thread for each scheduled operation

If you wanted to boil 100 eggs, would you buy 100 timers?

Upvotes: 5

Related Questions