Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 11 Nov 2004 15:36:53 +0100
From:      Ronald Klop <ronald-freebsd8@klop.yi.org>
To:        mcgregory@e-card.bg, freebsd-java@freebsd.org
Subject:   Re: Thread's type
Message-ID:  <opsha1jrjw8527sy@smtp.local>
In-Reply-To: <1100119160.700.13.camel@martin151>
References:  <1100119160.700.13.camel@martin151>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 10 Nov 2004 20:39:21 +0000, Martin Grigorov <mcgregory@e-card.bg>  
wrote:

> Hi all,
>
> I want to ask what type are Java threads in FreeBSD - green or native ?
> I'm using FreeBSD 5.3 and jdk 1.4.2 from ports, actually
> /usr/ports/jdk14.
>
> I am a little bit confused: a sysctl entry
> "kern.threads.max_threads_per_proc" says that one process can run max
> 1500 threads. But I wrote test and it crashes with:
> 'Exception in thread "main" java.lang.OutOfMemoryError: unable to create
> new native thread', after starting ~ 8300 threads in the Virtual
> Machine.
> So it sais "native" in the exception, but they are much more than 1500.

Java uses native threads.

About the 'kern.threads.max_threads_per_proc' limit:
The default thread support of FreeBSD 5 (libpthread) doesn't map userspace  
threads and kernel thread 1:1.
As long as a thread isn't executing in a part of the kernel it doesn't use  
kernel resources.
Use top -H to see all threads that are known to the kernel.

If you put this in /etc/libmap.conf you will use a 1:1 thread library and  
your program will give (the expected) errors around 1500 threads.

libpthread.so.1         libthr.so.1 # Everything that uses 'libpthread'
libpthread.so           libthr.so   # now uses libthr.

libc_r.so.5             libthr.so.1 # Everything that uses 'libc_r'
libc_r.so               libthr.so   # now uses 'libthr'

Because the N:M thread mapping a program can switch between threads  
without kernel overhead.

Ronald.

-- 
  Ronald Klop, Amsterdam, The Netherlands



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?opsha1jrjw8527sy>