One Java application but 2 processes java and javaw? - java

i'm a bit lost with my application.
I run only one swing application (one window) but in the task manager i have two processes : java.exe and javaw.exe bopth consuming resources.
I found that javaw.exe is used when there's no java console, that's the case of my app.
So i'm wondering why is a "java.exe" process running and used by my application?
My app is launched by an exe (by launch4j) maybe it comes from that?
thanks

Most likely launch4j runs a java.exe console, which in turns starts a javaw.exe for running your GUI application. java.exe is for console applications only.

Related

User is able to open the JavaFx desktop application more than once in a Windows machine

I am working on a JavaFX desktop application where the User is able to open the JavaFx desktop application more than once in a Windows machine. From Mac it cant be opened more than once.
The following code is used to launch the application:
Application.launch(ExampleApplication.class, (java.lang.String[])null);
Apart from JUnique library, is there any way to fix this issue ?
Any inputs will be helpful.
Application.launch() should only succeed once per a single application as per documentation. In addition it solely manages the current application and doesn't return until the application exits. If you want to be able to run the application more than once I'd recommend creating a standalone launcher for your application which runs a java process, which in turn runs your application. This way each time the launcher is executed a unique process is started and invokes the application.

Launch external app from java - and NOT have it tied to the VM

There are times when my big Java app needs to launch an external program.
I can do that pretty easily with
Runtime.getRuntime().exec("app name");
The problem is that the launched app seems to be tied to my Java process, as it gets terminated when my Java app then exits. I want to leave the other app running.
Edit: Made a mistake with above description.
The launched app does NOT get terminated.
The problem is that after my original app exits, I can not start it again UNTIL the launched app terminates. Original App (and launched app) are both Launch4J generated .exe's.
So, how can I keep the launched app from preventing a full exit from the original app?
(Oh, and just to throw another monkeywrench into it, the launched app uses a 32bit JVM, while the original app is running in a 64bit JVM.)
While the shell command trick might work, I did find an easier way.
Desktop.getDesktop().open("app name");
Apparently that launches the app in a way that does NOT stay tied to the original program.
One way that should work is by running a shell command that starts your program as an independant process.
For instance on Linux (based on this answer):
Runtime.getRuntime().exec(new String[] {"/bin/sh", "-c", "nohup app_name &"});
An on Windows:
Runtime.getRuntime().exec(new String[] {"cmd.exe", "/c", "start app_name"});

What does the jp2launcher do in the applet program?

Run a page which contains Java applet, notice that a process called jp2launcher is running. What does this process do?
It is part of the "Next Generation Java Plugin" (aka plugin2), the module responsible for starting the JVM for Applets or JNLP (WebStart). I think it also used to launch Java FX. I think it is used starting with Vista, on XP the java.exe is called directly.
Basically the process responsible for talking to the Browser and starting the Java VM. In case of Firefox that launcher is started instead of the "plugin-container" you see for other plugins (like Acrobat).

Cannot run two instances of java webstart

I am unable to run more than one instance of java webstart at any given time.
For example, I am unable to run both the production & QA instance of an application at once, both of which are launched via java webstart. Additionally, I am unable to run the java webstart cache viewer at the same time as either the production or QA instance of my application.
I am however able to run any of the above three webstart launches when they are run in isolation of each other. When I try to bring up a second option, I see the 'Java Loading...' screen which then disappears and nothing happens.
Additionally, I have tried to delete the webstart cache (via the java webstart cache viewer) and I receive the following error regardless of which JRE I point to:
"Bad installation. Error invoking Java VM (execv)
'path to my javaw.exe'"
I expect both the problems I mention above are interlinked. I do not believe I have changed any configuration recently and I have been happily running java webstart for years.
Has anyone seen such a problem before?
Thanks,
Jack
EDIT: When the second instance of webstart attempts to run, during the display of the 'Java Loading...' screen I can see in the task manager that a new javaw.exe process is spawned. This process almost immediately dies though. I'm not sure how to inspect the failure in that process, but I expect it is similar to the failure when trying to clear my cache through the webstart cache viewer.
You may be able to use javaws from the command line to run a second instance in -offline mode. The verbose option is handy, too.
javaws -offline -verbose MyApplication.jnlp
I think it is because both instances of the application use the same folder as current working directory. I do not remember exactly but it is somewhere under user home and the folder contains the application name or something...
So, if this is correct the solution is to change the application name like "My Application - QA" vs. "My Application" used on production.
The name is somewhere in jnlp.xml.
The reason may be the startup parameters for client java/javaw, which do not allow to run more than one instance of Java. For example because of set debug port. These parameters can be set in the command line or in the Java Control Panel -> Java -> button View.

Close a running program from java application

I open up an external application from my java application. How can I close this application from the same Java application?
thanks
The best you can do (without venturing into messy/complicated/platform specific stuff) is to call Process.kill() on the Process object you got when you started the external application.
I don't think this is guaranteed to close the application*, and there is a chance that it may cause it to close uncleanly; i.e. without giving the application a chance to save open files, etc.
* Indeed, on *NIX if you started a "setuid root" process from a non-root Java application, and the OS won't let it send any signals to to.
Why don't you have a batch (Windows) or script (*nix) file that start and stops that application, and then run your runtime.exec with the parameter start/stop?
UPDATE:
This may help: http://it.toolbox.com/blogs/database-solutions/kill-a-process-in-windows-bat-19875
Second Update
You can also search by exe name using: 'tasklist ^| findstr /i excel.exe'
On Windows this will fail. It's a top 25 bug (or maybe top 25 rfe), though it really isn't so much Java's fault ... On Windows any children of the parent process will not be killed when parent is killed..... and there are many ways to run afoul of this (cmd /c anything and you will be in game-over-land)

Categories

Resources