Details
-
Improvement
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
None
-
None
-
None
Description
I would like to propose some simple optional changes that would be activated by a compiler flag. These changes would enable a typical monolithic single threaded application to use libhdfs without the need to incur additional overhead for threads that is not needed.
Here is a proposed for these changes:
#1 add a new function to "jni_helper.c"
/** getSoloJNIEnv: A helper function to get the JNIEnv* for non-threaded use.
- If no JVM exists, then one will be created. JVM command line arguments
- are obtained from the LIBHDFS_OPTS environment variable.
- @param: None.
- @return The JNIEnv* for non-thread use.
- */
JNIEnv* getSoloJNIEnv(void)
{
JNIEnv *env;
env = getGlobalJNIEnv();
if (!env) { fprintf(stderr, "getJNIEnv: getGlobalJNIEnv failed\n"); return NULL; }return env;
}
Add the following the following to "hdfs.c"
#1 a static global variable : "JNIEnv* hdfsJNIEnv;"
#2 a MACRO: "GETJNIENV();"
#ifdef NOTHREAD
static JNIEnv* hdfsJNIEnv = NULL;
#define GETJNIENV() \
if (hdfsJNIEnv == NULL)
\
env = hdfsJNIEnv;
#else
#define GETJNIENV() env = getJNIEnv();
#endif
The above NEW MACRO would be used as in the following example:
int hdfsFileGetReadStatistics(hdfsFile file,
struct hdfsReadStatistics **stats)