Home

JNIEnv

JNIEnv is a pointer to a structure of function pointers that expose the Java Native Interface (JNI) for a thread calling into native code. In C and C++ native methods, the first parameter is typically JNIEnv* env, through which all JNI operations are performed. The env pointer represents the per-thread JNI environment and is valid only for the duration of the thread’s attachment to the Java Virtual Machine (VMI) or the duration of the native method call.

A native thread must attach to the JVM to obtain a JNIEnv*. If the native code is

JNIEnv provides access to functions for interacting with Java objects and classes, including FindClass, GetMethodID, GetFieldID,

In summary, JNIEnv is the thread-specific interface to JNI, enabling native code to interact with Java code

invoked
directly
from
Java,
the
JVM
supplies
the
JNIEnv*
for
the
duration
of
that
call.
If
the
native
thread
is
created
by
native
code,
it
must
call
AttachCurrentThread
to
obtain
a
JNIEnv*,
and
DetachCurrentThread
when
finished.
The
env
pointer
should
not
be
cached
for
use
across
threads
or
across
different
attachments.
NewObject,
CallObjectMethod,
and
conversions
between
Java
and
native
types
(for
example,
GetStringUTFChars,
ReleaseStringUTFChars).
It
also
includes
error
and
exception
handling
facilities,
such
as
ExceptionOccurred,
ExceptionDescribe,
and
ThrowNew.
The
environment
also
enables
creation
and
manipulation
of
Java
arrays
and
strings,
and,
via
GetJavaVM,
access
to
the
underlying
JavaVM
for
operations
such
as
attaching
threads
or
obtaining
a
new
JNIEnv
for
other
threads.
while
accounting
for
the
thread
lifecycle
and
JVM
attachment
requirements.