Java thread vs. native thread

1,883 views
Skip to first unread message

ls02

unread,
May 8, 2010, 9:18:19 PM5/8/10
to android-ndk
Does anyone know how Java thread relates to Android native thread?
Does it map one to one?

We have mission critical code that is not executed uninterruptedly in
Android java thread on some lower power Android devices. What would be
the best solution to address this problem? The mission critical code
itself is in native code however what we see is that on some devices
the thread in Java application layer that calls the mission critical
native code is not given enough priority and frequently interrupted by
other threads (for instance just rotating device suspends that thread)
though we boost its priority to highest level. We thought about
creating a pure native thread in NDK layer and set its native priority
to highest level. Maybe in this case it will not be interrupted by GC
and will execute more efficient.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

Ken Warner

unread,
May 8, 2010, 9:30:08 PM5/8/10
to andro...@googlegroups.com
I'm 99% sure that you cannot make a completely un-interruptible thread.
All threads eventually are managed and scheduled by the OS.

Although, maybe some of the Andrioid devices do let you create an
un-interruptible thread. It would be interesting to know how
you would eventually stop it because you couldn't interrupt it.

ls02

unread,
May 8, 2010, 9:43:41 PM5/8/10
to android-ndk
I understand that scheduler service is basic for all preemptive
multitasking systems and all threads are intrrupted and scheduled by
it. What I refer to unterrupted meanign it is not interrupted by GC or
any Java service.

To undertand what I could potentially gain by moving mission critical
code outside Java world into native world I need to know how Java
thread relates to native thread and what overhead it carries as a
thread.
> For more options, visit this group athttp://groups.google.com/group/android-ndk?hl=en.- Hide quoted text -
>
> - Show quoted text -

Ken Warner

unread,
May 8, 2010, 9:51:33 PM5/8/10
to andro...@googlegroups.com
Best take that to a SUN forum. You might get answers there.

ls02

unread,
May 8, 2010, 9:53:50 PM5/8/10
to android-ndk
I am not interested in general, I am interested in particular Android
case. Android Dalvik JVM implementation may very well be different
from other platforms.
> >> For more options, visit this group athttp://groups.google.com/group/android-ndk?hl=en.-Hide quoted text -

appforce.org

unread,
May 9, 2010, 5:57:04 AM5/9/10
to android-ndk

"What I refer to unterrupted meanign it is not interrupted by GC or
any Java service."

I suspect that by interrupt you mean switching execution context to
other thread, rather than terminating?

Preventing this should not be possible on scheduling OS-es, maybe the
best you can is to set highest thread scheduling priority. Note that
you need a real-time OS to execute mission critical code and Android
is not the proper environment - it's user oriented rather than mission
oriented. Running in VM or native doesn't make any difference, your
thread will always yield execution after some (very short) time. Link:
http://en.wikipedia.org/wiki/RTOS

ls02

unread,
May 9, 2010, 9:17:40 AM5/9/10
to android-ndk
I already reponded that I very well undrstand that scheduler is basic
component of pre-emptive multitasking and by interrupted by I meant
not scheduler but JVM.

My first question of Java thread maps directly to native thread.
Meaning if I create a Java thread in application layer, is a native
thread is created and all code in the Java threrad executes in the
native thread? Even if this is the case I assume this native thread is
yielded less time and can be suspended by GC and possibly other JVM
services to perform JVM overhead operations like garbage collection.

appforce.org

unread,
May 9, 2010, 3:04:13 PM5/9/10
to android-ndk
Dalvik threads maps 1:1 to pthread-s. Check in Android's source /
dalvik/vm/Thread.c - it's *very* well commented.

If all your worries are about GC-ing, that's within your process and
you have some indirect control over it - for example pre-allocate and
reuse your objects. There are APIs in Android that cause lots of GC-
ing so this may not work always.

Anyway, you shouldn't rely on OS-es like Android for mission critical
code.
Reply all
Reply to author
Forward
0 new messages