Threads

Java Link optionally supports automatic thread “JNI attachment” for threads created from C++:

target_compile_definitions(scapix PUBLIC SCAPIX_JAVA_AUTO_ATTACH_THREAD)

Alternatively, you can manually attach such threads:

#include <scapix/link/java/env.h>

void thread_func()
{
    scapix::link::java::attach_current_thread();

    // ...

    scapix::link::java::detach_current_thread();
}

Call attach_current_thread() at least once for each thread created from C++, detach_current_thread() is called automatically on thread exit. You may also manually call detach_current_thread() earlier if desired.