0

Up until yesterday I thought that the JVM did all of it's threading internally, allocating some of it's reserved memory to each thread and handling thread transition and executing exclusively within it's own logic.

However, yesterday I had a Java program die because it hit the linux ulimit, /proc//status showed the java app had 1023 threads allocated. This is not what I was expecting giving my understanding of the JVM.

Given this information it seems likely that the JVM is using a linux thread for each JVM thread it creates, is this correct? I expect the java spec doesn't say either way how threads are to be handled, and this would simply be a design choice of the JVM implementation I am using, but I'm still curious how this is implimented within my JVM.

Is the JVm using linux threads only for memory segregation, or does it use other features, specifically is it letting linux handle interrupting and dividing of time across threads?

Is there anything tricky about how the GC collects linux proc threads I should be aware of if I'm going to be tweaking my java configuration to try to prevent hitting my proc limit (it's believed they were dead but not yet collected threads).

dsollen
  • 6,046
  • 6
  • 43
  • 84
  • How could the jvm create a thread outside the OS control? – bichito Jul 28 '17 at 16:02
  • 1
    @efekctive You can create thread-behavior in user code. See [Green Threads vs Non Green Threads](https://stackoverflow.com/q/5713142/5221149). – Andreas Jul 28 '17 at 16:05
  • Thread-behavior is not a thread. The OP is how threads interact. – bichito Jul 28 '17 at 16:07
  • 2
    @efekctive The OP is asking about Java threads. In early versions of Java, threading on Linux and Solaris was done with non-OS threads, aka green threads. I said "thread-behavior" only to distinguish from native OS-threads ("true" threads). – Andreas Jul 28 '17 at 16:10
  • Green threads -> year 2000. Almost 18 years ago. Just by reading your link. This was pre-multithread support cpus. I do not see the relevance. Logging off – bichito Jul 28 '17 at 16:31
  • 1
    You misunderstand the relationship between threads and memory. There is no "memory segregation" between threads of the same process. Every thread in a given process see exactly the same virtual address space as every other thread. It doesn't matter whether they are green threads or operating system threads. The JVM is totally responsible for allocating the memory (including the call stacks) for its threads. The only thing the operating system does is decide which thread gets to run on which processor and when. – Solomon Slow Jul 28 '17 at 16:54

0 Answers0