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)
| 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); |