MCPcopy Create free account
hub / github.com/java-native-access/jna / detach

Method detach

src/com/sun/jna/Native.java:2499–2519  ·  view source on GitHub ↗

Indicate whether the JVM should detach the current native thread when the current Java code finishes execution. Generally this is used to avoid detaching native threads when it is known that a given thread will be relatively long-lived and call back to Java code frequentl

(boolean detach)

Source from the content-addressed store, hash-verified

2497 called on a thread created by the JVM.
2498 */
2499 public static void detach(boolean detach) {
2500 Thread thread = Thread.currentThread();
2501 if (detach) {
2502 // If a CallbackThreadInitializer was used to avoid detach,
2503 // we won't have put that thread into the nativeThreads map.
2504 // Performance is not as critical in that case, and since
2505 // detach is the default behavior, force an update of the detach
2506 // state every time. Clear the termination flag, since it's not
2507 // needed when the native thread is detached normally.
2508 nativeThreads.remove(thread);
2509 Pointer p = nativeThreadTerminationFlag.get();
2510 setDetachState(true, 0);
2511 }
2512 else {
2513 if (!nativeThreads.containsKey(thread)) {
2514 Pointer p = nativeThreadTerminationFlag.get();
2515 nativeThreads.put(thread, p);
2516 setDetachState(false, p.peer);
2517 }
2518 }
2519 }
2520
2521 static Pointer getTerminationFlag(Thread t) {
2522 return nativeThreads.get(t);

Callers 1

callbackMethod · 0.95

Calls 4

setDetachStateMethod · 0.95
putMethod · 0.80
removeMethod · 0.45
getMethod · 0.45

Tested by 1

callbackMethod · 0.76