Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7163833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:58:08+00:00 2026-05-28T13:58:08+00:00

Is it feasible to attach a native thread permanently to the JVM (AttachCurrentThread) (or)

  • 0

Is it feasible to attach a native thread permanently to the JVM (AttachCurrentThread) (or) is it better to attach when ever required (calling java functions) and detach immediately once the work is done

I wrote a sample native app with the above cases, didn’t find any difference. But by googling, vaguely I came to know that, when attached to JVM , JVMs thread scheduling is responsible for scheduling else OS will schedule the native thread (if not attached). Is this true?

It is important to detach any thread that has been previously attached; otherwise, the program will not exit when you call DestroyJavaVM. – http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jniref.html#attach

Will there by any performance issues?
Please let me know if anyone knows, its one my important design aspect.

Thanks & Regards.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:58:09+00:00Added an answer on May 28, 2026 at 1:58 pm

    Generally speaking, the main performance cost is the thread creation at OS level. Either the thread is creating natively and then attached or directly created as java.lang.Thread from Java API.

    If you re-use the same native thread, performance will be good. By the way, do not create dozens of native threads.

    The JVM does not schedule threads itself. It may force them in sleep state for various reason like garbage collection. In that specific case, it has to wait for a JNI call from a native thread before collecting. So you have to avoid too long code execution without JNI call to keep the VM heap consumption low.

    Moreover, you have to take care to call DeleteLocalRef before detaching a native thread or else your VM will leak memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking into game programming in Java to see if it is feasible.
Mac OS 10.7 (Lion) comes with JDK 1.6 and java 6. Is it feasible
How feasible would it be to compile Python (possibly via an intermediate C representation)
Is there any feasible way of using generics to create a Math library that
Is it feasible (financially) to host centralised mercurial repositories on Amazon S3. As far
Short version: Is it easy/feasible/possible to program modal window in Flash (AS3)? Is there
Does anyone know if it is feasible to write a Generic JMS client -
Maybe this isn't really feasible. But basically, I've been developing a snippet-sharing website and
For an image hosting web application: For my stored images, is it feasible to
I want to port few C/C++ libraries to Android, how feasible it would be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.