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 7946067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:02:43+00:00 2026-06-04T01:02:43+00:00

I have a Windows MFC application that: (1) Loads the JVM ( JNI_CreateJavaVM() )

  • 0

I have a Windows MFC application that:

(1) Loads the JVM (JNI_CreateJavaVM())

(2) Attaches the main thread to the JVM (AttachCurrentThread())

(3) Loads some Java classes and methods (FindClass() and GetMethodID() / GetStaticMethodID())

(4) Registers some native callbacks for use by Java code (RegisterNatives())

(5) Detaches the thread from JVM (DetachCurrentThread())

(6) Destroys the JVM (DestroyJavaVM())

All of the above functions succeed every other time I run the application. I know they succeed, because, additionally to the above, I interact with the application and successfully call Java static methods, and these Java methods successfully call my native callbacks. My application exits gracefully, and it is certain that the expected Java functions, and native callbacks, have been executed.

However, every other time that I run the application, the call to JNI_CreateJavaVM() fails (not populating the JavaVM *). Absolutely nothing changes between runs of the application. I simply run it once (successfully, even without doing anything except the above 6 steps), quit gracefully, run again, and it fails, back and forth. There are no exceptions to the back-and-forth success/failure – I can run it dozens of times, and it oscillates precisely every other time between success, and failing on the JNI_CreateJavaVM() line.

If necessary, I will paste more code. However, I hope somebody has an insight with what I’ve provided. (Note: this is a BCGSoft MFC property-sheet application, though I strongly doubt that matters.)

  • 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-06-04T01:02:45+00:00Added an answer on June 4, 2026 at 1:02 am

    It looks like you are running into this bug (restated here) that is probably never going to be fixed.

    Despite its name, DestroyJavaVM() does not actually destroy the JVM. What it does is signal the JVM that it should shut down, but the JVM actually waits until all the threads other than the Main thread have stopped before it actually shuts down. In fact, even then it does not fully clean up after itself, as the documentation states (quite cryptically): "The JDK/JRE still does not support VM unloading, however."

    Also, I’m concerned about your step 2, "Attaches the main thread to the JVM". You do not need to attach the thread that created the JVM to the JVM and you may not detach that thread. If you really are doing that, then it’s possible that is what is messing up your system. (The thread that creates the JVM is the JVM’s "Main" thread. You only need to attach/detach other native threads to the JVM if they need access to it.)

    By the way, JNI_CreateJavaVM() returns 0 on success, and you say it returns 0 the "failed" times, so in what sense is it failing? Which JVM (version, vendor) are you using?

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

Sidebar

Related Questions

On a Windows Mobile 5.0 device I have an MFC C++ kiosk application that
I have a MFC application that launches a IWebBrowser2 window. On users computers where
I am developing windows CE 6.0 for VIA board. I have a MFC application
I'm working on a bug where I have an MFC application that does weird
I have an application build with VS2008 SP1a (9.0.30729.4148) on Windows 7 x64 that
We have a windows MFC app that is written against an access database on
I have a Windows mobile 4.0 application, written using EVC++ 4.0 SP4 with MFC,
I have an MFC application that spawns a number of different worker threads and
We have a MFC 8 application compiled with /CLR that contains a larger amount
I have a mature MFC C++ application that displays on screen and prints using

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.