[EMAIL PROTECTED] wrote:
>
> Q1: There are only two ways to create new threads when use
> JNI on Linux (and other OS).
> (a) use Thread.start in java code.
> (b) let native code create a thread by using pthread_create and
> attach the newly-created thread to JVM, so JVM, the multi-
> threaded application, will create a sort of "internal thread"
> for the attached native thread, right?
Right. The JVM has its own bookkeeping requirements for managing
threads, attaching allows the JVM to learn about a thread it didn't
create.
>
> Q2: if use the first method, to make the new thread be created in
> OS kernel, we need to use "java -native" to run the application.
> If use "java -green", then the new thread won't be created in
> OS kernel and it's fully controlled by JVM therefore it's in
> user space and non-preemptive.
>
> if use the second method, we have to use "java -native" to run
> the application because native code uses native lib
> (pthread_create) to create the thread. If "java -green" were
> used to run it, would run into problems.
>
> Do I understand them right?
It's simpler than that: to avoid strange and unpredictable behavior, the
thread mechanism used by the native code should be the same mechanism
that's used by the JVM. You can't use the green threads from native code
- the API isn't published - so you need to use native.
>
> Q3: With BlackDown 117_v3, the default behavior should be "green".
> I can run a simple java application with "java app" or
> "java -green app" without any problem (they are the same,right?).
> But got an error msg like "java was not found in
> /usr/local/jdk117_v3/bin/../bin/i686/native_threads/java" when
> run it with "java -native app". Do I miss something?
>
> Q4: What compile options I need to specify to pick up the right lib
> if I want to run java app with green or native thread?
No changes needed with compiling. The reason you can't run native is
that you don't have a native version installed in your JDK installation
tree. Visit a mirror site and grab jdk_1.1.7-v3-glibc-x86-native.tar.gz:
unpack it from the $JAVA_HOME directory and you'll get the native
versions.
By way of background, the decision on which threading model to use is
made in the script ($JAVA_HOME/bin/java) that launches the java
executable: it looks at "-green" or "-native" (yes, it defaults to
green), sets up the environment, and decides which actual executable
(green or native) to run.
Nathan
>
> Thank you.
>
> Lee
>
> -----Original Message-----
> From: Nathan Meyers [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, January 18, 2000 2:20 PM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: Re: JNI and Dead Thread on Linux
>
> On Tue, Jan 18, 2000 at 11:28:17AM -0600, [EMAIL PROTECTED] wrote:
> > Hi:
> >
> > I got a few questions on JNI on Linux. It would be appreciated if someone
> > could help.
> >
> > Suppose a shared library file has a function that is used to do hardware
> > I/O, say hard drives R/W. A Java application uses JNI and calls this
> native
> > function in .so file twice to R/W two separate hard drives at the same
> time.
> > In this way, we should have two new threads (light weight processes) t1
> and
> > t2 created (am I right?).
>
> Calling into native code doesn't create new threads - it just moves the
> flow of control from the Java interpreter into some other native code.
> After the JNI method returns, you're back to executing native code in the
> Java interpreter.
>
> Nathan
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]