This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer (Exam 1Z0-830) Java SE 17 Developer (Exam 1Z0-829) Programmer’s Guide and have Khalid Mughal and Vasily Strelnikov on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

JNI and C++

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there. I was hoping you could lend some insight into a little problem we
have.
I am a Java developer and I am working with a C++ developer to make an
extension to an existing Win32 application.
We have written the add in using java and swing and we are using C++ to tie
the java code to the existing application.
We have been using JNI (obviously) and we can launch our program from a C++
executable by instantiating the JVM and using general JNI techniques.
However, when we plug our add-in into the existing application and launch
it we have some problems. It launches ok and seems to run fine but when we
close the java add in, it also shuts down the parent application.
Our java add in basically launches a Swing gui. When we close the java GUI
frame we seem to close everything and can't run any of our C++ code that
exists after the instantiation of the Java add in. I read our article and
studied your code and it all seems very similar. I'm thinking this may be
an issue with how this add in is handled as a thread and how the
instantiation of the JVM is handled in the JNI code. I'm reaching here
since I am not a C++ guy and threading is something I know little about at
present. I use the System.exit(0); as a means of closing the application
and initially thought that may be a problem; but, you seem to do the same
thing in your article. Any ideas?
Any advice you could give us would be greatly appreciated. Thank you.
David Shepherd
Noonetime, Inc
Java Developer
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try DestroyJavaVM to unload the JVM. Also you may want to detach any threads that are active before destroying the JVM.
 
David Shepherd
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dean Jones Jr:
Try DestroyJavaVM to unload the JVM. Also you may want to detach any threads that are active before destroying the JVM.


I am doing both of those things. This is not an executable but rather is being launched from within another application. I am wondering if this is part of the problem. When we close the java add in application id kills the parent application also.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This sound quite like the problem I'm struggeling with.
I have noticed that calling DestroyJavaVM doesn't return until, well never...
Im currently trying to make a Win32 wrapper for a Java application. The wrapper should be able to run both as a service and as a normal application. When I invoke the java app in win32 service mode all is fine since Windows SCM keeps the win32 app alive and thus also the 'internaly' loaded JVM, but when run as a normal the win32 app terminates an unloads the JVM too so I called DestroyJavaVM and al is well until I exit the Java app then the JVM unloads and the win32 app just exits!! The DestroyJavaVM does not even return so eventual cleanup, releasing and unloading of libs is left to the system to handle since the win32 app is just plainly killed right out on the spott. So what I would like is to find a way to get noticed about when the Java app is terminated so that I may cleanup, close and free things in the win32 app before getting killed.
Does anyone know a way to acomplish this?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic