- using javaw to run jars in batch files results in more than one java processes in process explorer — XYNTService
- Many instances of javaw.exe
- Many instances of javaw.exe
- How to differentiate between different JavaWS applications from the list of processes in the task manager process list?
- Manage JAVA processes under Windows
- How to find and kill running Win-Processes from within Java?
- How to distinguish two running java processes on Windows?
- Run multiple processes of a same class using ProcessBuilder
- 1 Answer 1
- Method 1, cloning
- Method 2, array of arguments
- Gradle Daemon appears to start multiple java exe
- 1 Answer 1
- Related
- Hot Network Questions
- Subscribe to RSS
using javaw to run jars in batch files results in more than one java processes in process explorer — XYNTService
I have a somewhat strange issue. I have a java application that installs few services that run as Jars. Previously I used installed Java to run these Jars. There are four services and all will be instantiated from a single batch file with sequential call to each other. Something like this,
start %JAVA_HOME% commandtoruntjarfile
would work and all four services will run in the background and only one java.exe visible in process explorer. So I had another service installed as windows service which would start stop these services by calling the run bat or shutdown bat. Now the customer requirement changed to using an internalized version of java. I extract java to a location, make our own environment variable name «ABC_HOME» and the required syntax in batch changes to
%ABC_HOME%\javaw commandtorunjarfile
When its run it works. but there is no stopping these. When I go to process explorer I see 4 java.exe running each for the four run commands in the batch file. If I stop the windows service all the four keep working. If I restart the windows service the number of java.exe in process explorer goes to eight and keeps going up until windows has had enough of it. How do I get around it? I think the solution should be to have the one java process in process explorer but I cant seem to find any solution for that. [EDIT] The four sub services are actually XYNT processes. In the normal scenario it would be something like this [Process1] CommandLine = java -Xrs -DasService=yes -cp jarfiles WorkingDir = c: bin scache PauseStart = 1000 PauseEnd = 1000 UserInterface = No Restart = Yes For using java from a specific location the following change was needed
CommandLine = %JAVA_PATH%\bin\java.exe -Xrs -DasService=yes -cp jarfiles
but this wouldn’t work as it would not accept the path variable in XYNT.ini file. so I called a batch file here and in that batch file I used the above code. So here is what the change looks like,
CommandLine = batchfile.bat
%JAVA_PATH%\bin\java.exe -Xrs -DasService=yes -cp jarfiles
Many instances of javaw.exe
What I need is to see, what parameters Java process was started with (e.g. Main class) and be able to shut process down. My question being if the user has launched multiple JavaWS applications then how can we identify the process which we want to check?
Many instances of javaw.exe
Task Manager shows many instances of javaw.exe residing in memory making windows run out of memory. I’m using this code to close my java application:
SwingUtilities.invokeLater(new Runnable() < public void run() < Form1 frame = new Form1(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); >>);
How can I fix this problem?
Use ProcessExplorer instead of TaskManager.
Select one of the javaw.exe processes, go to the image tab, and you will be able to see the full command line.
This will help you to determine what the javaw.exe processes actually are.
Firstly ensure %JAVA_HOME%/bin is set in your PATH and %JAVA_HOME% is pointed to your JDK.
Then to leverage these JDK tools,
use jps -l to list all the java processes.
use jstack -l to check the stack trace and you can find some clues.
frame.addWindowListener(new WindowAdapter()
Windows 7 — Multiple instances of java.exe and, Keep all of them. If there is a java.exe in a subfolder of a program folder, it is probably safe to assume that the program whose folder java.exe is in uses that …
How to differentiate between different JavaWS applications from the list of processes in the task manager process list?
I am using JavaWS to launch an application, then how to check whether that application is running or not in the user’s machine as it’s name in the Task manager process list is not what I gave in the JNLP file.
NOTE. I checked the task Manager process list but there the name of the process is javaw.exe and all the applications which are using JavaWS will have the same name. My question being if the user has launched multiple JavaWS applications then how can we identify the process which we want to check? I thought of getting the PIDs of the process but unfortunately there wasn’t any way to get the PIDs of the process. I am working on Windows.
..how to check whether that application is running or not in the user’s machine..
There’s no need to resort to examining processes, an inherently OS specific approach.
The JNLP API offers the SingleInstanceService which..
..allow(s) applications launched under Java Web Start to register themselves as singletons, and to be passed in new parameter sets when user attempts to launch new instances of them.
Your code will then get to decide whether to update the current app., bring it to the front, or launch a new instance.
On Windows7 you can select list of colums to display in the Task Manager.
Go to View -> Select Process Page Columns
and select Command line column to be displayed.
You should be able to differentiate between different javaw processes by the command line which includes the class path, Main class name etc.
Should I be concerned about javaws.exe running 1000’s, About 5 minutes after every Start, Restart or Log-off/log-on, jsched.exe*32 will start javaws.exe, up to 15,000 Image Names build in Task …
Manage JAVA processes under Windows
How do I manage Java processes in Windows environment. What I need is to see, what Parameters java process was started with (e.g. Main class) and be able to shut process down.
Check for java.exe , javaw.exe and javaws.exe .
java.exe is a Win32 console application. This is provided as a helper so that, instead of using jvm.dll we can execute java classes. As it is a Win32 console application, obviously it is associated with a console and it launches it when executed.
javaw.exe is very similar to java.exe . It can be considered as a parallel twin. It is a Win32 GUI application. This is provided as a helper so that application launches its own GUI window and will not launch a console. Whenever we want to run a GUI based application and don’t require a command console, we can use this as application launcher.
javaws.exe is used to launch a java application that is distributed through web.
For more info REFER
Java — How To stop an Executed Jar file, You can identify the process in taskmanager by looking for «java» or «javaw» processes. The problem will be in case you are running more than one …
How to find and kill running Win-Processes from within Java?
I need a Java way to find a running Win process from which I know to name of the executable. I want to look whether it is running right now and I need a way to kill the process if I found it.
private static final String TASKLIST = "tasklist"; private static final String KILL = "taskkill /F /IM "; public static boolean isProcessRunning(String serviceName) throws Exception < Process p = Runtime.getRuntime().exec(TASKLIST); BufferedReader reader = new BufferedReader(new InputStreamReader( p.getInputStream())); String line; while ((line = reader.readLine()) != null) < System.out.println(line); if (line.contains(serviceName)) < return true; >> return false; > public static void killProcess(String serviceName) throws Exception
public static void main(String args[]) throws Exception < String processName = "WINWORD.EXE"; //System.out.print(isProcessRunning(processName)); if (isProcessRunning(processName)) < killProcess(processName); >>
You can use command line windows tools tasklist and taskkill and call them from Java using Runtime.exec() .
Here’s a groovy way of doing it:
final Process jpsProcess = "cmd /c jps".execute() final BufferedReader reader = new BufferedReader(new InputStreamReader(jpsProcess.getInputStream())); def jarFileName = "FileName.jar" def processId = null reader.eachLine < if (it.contains(jarFileName)) < def args = it.split(" ") if (processId != null) < throw new IllegalStateException("Multiple processes found executing $ids: $ and $") > else < processId = args[0] >> > if (processId != null) < def killCommand = "cmd /c TASKKILL /F /PID $" def killProcess = killCommand.execute() def stdout = new StringBuilder() def stderr = new StringBuilder() killProcess.consumeProcessOutput(stdout, stderr) println(killCommand) def errorOutput = stderr.toString() if (!errorOutput.empty) < println(errorOutput) >def stdOutput = stdout.toString() if (!stdOutput.empty) < println(stdOutput) >killProcess.waitFor() > else < System.err.println("Could not find process for jar $") >
There is a little API providing the desired functionality:
What is the difference between «system32\\java.exe», When I run this command for %i in (java.exe) do @echo. %~$PATH:i, I get this output: C:\WINDOWS\system32\java.exe When I check my PC, I found …
How to distinguish two running java processes on Windows?
I have some code to run java.exe with command line to launch a game. Since I don’t players launch more than one game program instance at same time, so I need to check whether the game has been running or not. For normal exe file, I can get exe path from process information. But for java game, the execute file path is always the java.exe or javaw.exe ‘s path. So I have thought to get the command line information to get the jar file running. But there is the reason why I can’t get the command line:
Remember that from Win32’s point of view, the command line is just a string that is copied into the address space of the new process. How the launching process and the new process interpret this string is governed not by rules but by convention.
So, I need another way to do such thing, but I can’t thought out any method to distinguish two java process. Anyone could give me some tips?
Set up a named Mutex from your Java code. If the call to CreateMutex succeeds, this is the first instance. If it fails with error code ERROR_ALREADY_EXISTS , it’s not the first instance.
@IInspectable That’s a good point, but I can’t change the Java code for some reason. Is there another way?
Move that to your launcher application then, and keep the launcher process around, until java.exe returns (presumably when the game terminates). This won’t keep an attacker from launching the game multiple times, though. It’ll only keep people launching the game through the launcher from running that multiple times concurrently.
If you cannot change the Java code, why do you presume, that gathering the command line that launched said Java code would be of any help? Also, the user doesn’t have to kill your launcher process, to start a new game instance from the command line. After all, the user can inspect the command line you passed to java.exe to launch the game, using tools like Process Explorer. Unless you modify the actual game code, you will have to live with a half-assed solution.
Run multiple processes of a same class using ProcessBuilder
I want to have a main class in which users define how many Customer class processes they want to start. How do i solve this in my main? Below is the code I use to run Customer class once.
try < ProcessBuilder customer = new ProcessBuilder("java.exe","-cp","bin","lab_3.Customer"); Process runCustomer = customer.start(); runCustomer.waitFor(); >catch (IOException e) < // TODO Auto-generated catch block e.printStackTrace(); >catch (InterruptedException e) < // TODO Auto-generated catch block e.printStackTrace(); >
1 Answer 1
Method 1, cloning
I don’t know how good idea it is but, you could try doing something like this:
ProcessBuilder customer = new ProcessBuilder("java.exe","-cp","bin","lab_3.Customer"); Process runCustomer = customer.clone().start();
The .clone() will make a copy of it and then start the process from it. Now you can do:
ProcessBuilder customer = new ProcessBuilder("java.exe","-cp","bin","lab_3.Customer"); Process runCustomer1 = customer.clone().start(); Process runCustomer2 = customer.clone().start(); Process runCustomer3 = customer.clone().start(); Process runCustomer4 = customer.clone().start();
Method 2, array of arguments
Also you could store your arguments in an array and every time you want to start new Process , you would just create a new instance of ProcessBuilder , like so:
String command = "java.exe"; String[] args = new String[]< "-cp", "bin", "lab_3.Customer" >; for(int i = 0; i
And like this, if you need to store created Processes :
String command = "java.exe"; String[] args = new String[]< "-cp", "bin", "lab_3.Customer" >; Process[] processes = new Process[numOfProcesses]; for(int i = 0; i
Gradle Daemon appears to start multiple java exe
I have upgraded to Gradle 6.8.1 and Eclipse Buildship 3 on Windows 10 64 bit. There are issues with older gradle projects. So I decide to start a new Eclipse project and copy source over to the new project. As Eclipse starts a Gradle Daemon, there is a hang. There are multiple java.exe starting in the task manager. What on earth is going on? The only way out is to taskkill /IM java.exe /F UPDATE I go to the command line and run gradle it also attempts to start large numbers of daemons without cleaning anything up. It starts with Starting a Gradle Daemon, 1 busy Daemon could not be reused, use —status for details
UPDATE I’ve rolled back to Gradle version 6 and up came Windows Firewall to allow java.exe and the daemon works.
If I try and install 6.8.1 having Firewall access there’s the same issue. If I turn off the Firewall the same problem. It did not fix the problem though, Eclipse still starts multiple versions of java.exe when trying to create even a blank Gradle project. AAAAArgh!!
1 Answer 1
What I did to resolve this was uninstall and reinstall Eclipse. without a separate Gradle instance:
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.27.43548
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.