This discussion is archived
2 Replies Latest reply: Sep 15, 2009 8:08 AM by 843802 RSS

Problem in closing JVM

843802 Newbie
Currently Being Moderated
Hi all,
I am running an applet using the new java plugin. I like it, and I had to use it because I create an applet tag (using deployjava.js) witch is based on a jnlp file with many extensions.
My applet access TWAIN using the morena toolkit. This toolkit require to start a thread that will load twain.dll via LoadLibrary. I need a specific thread since all calls to this library methods need to be executed via the same thread.
Then I also use log4j. Log4j uses static variables in order to keep its configuration shared.
When I close my applet, in the destroy() method, I call TwainManager.close() and LogManager.shutdown().

If the user moves from my page to a different page, the destroy() method is called and my applet is closed. This operation does not immediately close the JVM. the JVM is closed inbetween 5 and 30 seconds later my applet is destroyed.

When the user reload my applet on the same JVM, it cannot access anymore twain, because it creates a new thread that cannot load the same twain.dll library.

If the user load the page once the JVM is unloaded (I may see jvm unloading because its console window get closed), the a new JVM is loaded and everything works perfectly.

I wrote a few information about the log4j since previously I didn't call the shutdown() method. Probably this was a reason for keeping the JVM loaded, but I do think that actually there are no reasons for keeping the JVM loaded.

So, my questions:
1. how may I be sure the JVM is closed, or how may I check what is blocking JVM from closing?
2. is there any way to instruct java plugin to create a new JVM every time my applet is run?
3. if the user is browsing a different page on a different window, will this share the same JVM as my applet? Will this block any possibility to my applet to load again the twain.dll?

Thanks,
Giuseppe
  • 1. Re: Problem in closing JVM
    843802 Newbie
    Currently Being Moderated
    So, my questions:
    1. how may I be sure the JVM is closed, or how may I check what is blocking JVM from closing?
    2. is there any way to instruct java plugin to create a new JVM every time my applet is run?
    Try
    <PARAM name="separate_jvm" value="true">
    See [https://jdk6.dev.java.net/plugin2/#SEPARATE_JVM]. I didn't try it but I I'd expect that everytime your applet gets loaded, a separate VM will be launched, and the old one(s) are closed behind the scenes.
    3. if the user is browsing a different page on a different window, will this share the same JVM as my applet?
    As far as I understand, if you dont specify the separate_jvm flag, the behaviour is not specified. See [http://forums.sun.com/thread.jspa?threadID=5396118].
    Will this block any possibility to my applet to load again the twain.dll?
    Likely. Using the separate_jvm flag should avoid that, but you always have to load your application and .dll's each time the applet is started. Thus, caching of applet data among multiple started applets seems impossible right now...
  • 2. Re: Problem in closing JVM
    843802 Newbie
    Currently Being Moderated
    Thanks,
    this is the solution I was looking for.