#include #include #include // a very simple signal handler which, unless signal chaining is used // will override JVMs signal handler void mySigHandler( int sig ){ printf("mySigHandler received signal: %d \n", sig ); signal(SIGINT, mySigHandler); } /* This example illusrates a possible problem of overriding JVM's signal handler. */ int main() { // create a JVM JNIEnv *env; JavaVM *jvm; jint res; JavaVMInitArgs vm_args; JavaVMOption options[1]; options[0].optionString = "-Djava.class.path=/home/paul/jniSC/src/testJNI.jar"; vm_args.version = JNI_VERSION_1_2; vm_args.options = options; vm_args.nOptions = 1; vm_args.ignoreUnrecognized = JNI_TRUE; /* Create the Java VM */ res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args); if (res < 0) { printf("Failed to create a JVM\n"); return 1; } else { printf("successfully created JVM\n"); } // when JVM is created and initialized. Register a signal handler. Unless signal chaining is used // this will override JVMs signal handler. This will result in JVMs signal handler never being invoked. signal(SIGSEGV, mySigHandler); printf("Registered handler for SIGSEGV: %d \n", SIGSEGV ); // find class jniProgressBar jclass cls = env->FindClass("jniProgressBar"); if (cls == NULL) { printf("Failed to find a class jniProgressBar\n"); } else { printf("succcessfully found a class jniProgressBar\n"); } // find method id for addProgressBar method jmethodID addProgressBar = env->GetStaticMethodID( cls, "addProgressBar", "()V" ); if( addProgressBar == 0 ){ printf("failed to get addProgressBar method id\n"); return 1; } // call Java addProgressBar method repeatedly while( 1 ){ env->CallStaticVoidMethod( cls, addProgressBar ); printf("in C++\n"); } return 0; }