java : Extend Applet process timeout - java

While running a java Applet in browser, a process java.exe starts and a java console appears if enabled. As long as the process is alive, the console is visible indicating the same.
This process doesn't exit if I to other page or even close the browser. It terminates automatically after some random time. Is there a way to control that time duration?
I've a functionality that starts with an applet , then navigate to some other page for completion. To use it again I return to applet page and here the applet initializes again if the process is already terminated which takes some time. I'd like to extend this time if possible so that applet doesn't initialize again.

Is there a way to control that time duration?
No. (Unless you wrote the browser.)
But your question indicates you have the entire wrong view of what an applet is and should be. That question indicates you think the applet/JVM should be 'in command' of the web pages/browser, whereas it is really just a guest in the web page. The browser/page controls the applet/JVM, not the other way around.

Related

How to run java once on window start up?

Due to a suite of antivirus and security policies, a java applet I developed for my organization loads very slowly. The problem is not the cache or the applet, but rather it's JVM. When Windows first loads, if I go to command window and enter "java", it will take nearly a minute for the response (the command usage text) to come up. Subsequent commands are responded immediately.
So, one mitigation I can think of is to set all users to run java once as they login. I can either put a shortcut to Start Up folder in the start menu, or create a registry key. If I want this to be as least intrusive as possible (load it in background and in low priority), what's the best way to do this?
Did you consider Windows Task Scheduler and task that starts on windows start-up?
You can add the call to java to the registry, under
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
http://msdn.microsoft.com/en-us/library/aa376977(v=vs.85).aspx
But what about not using java?

Trapping Java applet cancel button

I have a Java applet that runs with no UI and sends XML back to the calling Javascript for processing to a database. I have the applet set up to do a callback once the applet is initialized using an Init override and the callback is a Javascript function that proceeds to do some work with another applet method.
If the user clicks the "No" button on Java security warning however, no applet code is ever run and the calling page waits forever for the callback to occur. Is there a way to trap the user declining the security warning in Javascript?
Please no questions on why I'm using an applet for this, it's a very complicated infrastructure (out of my control) which involves multiple web vendors and this is the only architecture I've found that meets all the other requirements.
About the best you can do is poll for the applet appearance in JS, and if it doesn't appear after a 'length of time', pop an alert to the user offering to redirect to help (or wait - if they are still looking over the details offered by the security dialog/pop-up).
Use applets, expect trouble. Use hidden applets, expect chaos..

How to finish java.exe process in applet?

There is an applet on a HTML page. That applet loads a dll library and communicates with an external application through it. I can successfully load and work with that library. That library has functions INIT() and DEINIT().
The issue is when I try to call those functions again, the external app/library says that there is only one process can access to that app. It is an internal check. So I need a way to stop the Java process in order to start the app once again. But if I start the applet once, the Java process doesn't finished until I close the browser tab (or even the whole browser).
Is there a way to stop the Java process in the scope of the browser tab? And I need Java to start as soon as applet in the HTML page will appear.
You can't stop the JVM from the applet, it's managed by the browser.
You might consider switching to a Java Web Start application instead, it's started in its own VM.

restart java.exe from an applet

I have an applet packaged with a third part dll (from JTwain). My applet scans documents from the TWAIN compatible default printer. The applet fails on a paper jam and won't recover. The user navigates away from the page and the applet is destroyed. When returning to the page it fails again. Closing the browser (which kills java.exe process on the pc), and then returning to the page clears the problem and everything works.
I want to restart everything without requiring users to close down the browser. I've added a GUID query string to the URL's from which the applets resources are loaded - so I know nothing is being cached. I've checked in the windows task manager and there is no process created by the dll, it's all happening within the main java.exe process. I tried wrapping the scanning process in a thread so I could interrupt it in the stop or destroy methods (just in case the applets thread weren't stopped when the applet was destroyed), but that didn't work.
Any suggest would be greatly appreciated. Ideally I'd like some way to restart java when the applet unloads (but I doubt that's possible).
UPDATE
I've spent a couple of days trying to identify what causes the applet to fail. I still don't know :(
When the paper jam occurs something (not my code), is producing a couple of popups. The first alerts the user of the jam, and can be closed by clicking the OK button. The second says 'reading from device' and hangs. It cannot be close with the red, close window, icon in the top corner - I kill it from the task manager and windows asks to send a report regarding the 'non-responsive program'. I assume these popups are produced by the dll. And given that the second hangs, my assumption is that a thread started by the dll has hung while retaining a lock on some component of the TWAIN application. I get
com.asprise.util.jtwain.JTwainException: Failed to open the specified data source:
Source: TW-Brother MFC-9970CDW LAN Thrown
..when I try to access the scanner.
I'm at a bit of a loss as to how I can get more information. I'm testing my applet on a windows virtual pc (so as to use ie7), and don't have a method for step debugging in this environment. (And it's crashing on third party code for which I have no source anyway)
I see only two practical options here:
Use an API that handles paper jam without problems. Of course, that is easy to say (get robust API), harder to find.
Launch the app. free floating using Java Web Start. If it freezes up, the user can kill it and click the link for another instance in a new JVM. Or the applet might also call BasicService.showDocument(URLof.jnlp) if it can detect a problem with the DLL and is not itself frozen.
Of course, you should also report the bug to the ..Asprise(?) developers. The optimal solution would be to have the problem fixed at its source. Anything we do here is a 'workaround'.

How to Remotely Block and Unblock any application on Windows

I am creating a program using Java Sockets in which I capture the client desktop and send messaging to client. Its working properly but now I want to block Client applications like Notepad, MS-Word, etc.
How can I do this?
Thanks.
It is hard to do using pure java API.
I do not know what do you mean when you say "block". The easiest way is to check from time to time running processes and kill one named "notepad" by executing taskkill from java.
If you wish to achieve effect of inactivity of application, i.e. user sees the notepad but cannot type you can do the following.
You have to check which application is on front. There is no clean pure java solution for this but you can probably write VBScript or JScript that does this task and run it from java. Once you detected that notepad is on top create transparent window (or even probably half-transparent window) that occupies full screen. Bring it on top. User will not be able to type into notepad because your window is on top but will see it.
Here is reference how to create transparent windows: http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/
Good luck.

Categories

Resources