?
Solved

How to kill a Java program with an infinite loop?

Posted on 2008-10-02
7
Medium Priority
?
1,304 Views
Last Modified: 2013-12-29
I have a Java class called TestThread.java. Below is the code. I have a Windows batch file that will run the class file. When I run the batch file, "Hello world!" will be printed out every 30 seconds.

I then modified the java file to print out "Goodbye everyone!" instead of "Hello world!", compiled it, and then replaced the original class file with the new one. Now, in addition to "Hello world!" being printed out every 30 seconds, "Goodbye everyone!" is also printed out every 30 seconds.

How do I kill the Java program that keeps printing out "Hello world!"?

This is a simplified explanation of my actual program that doesn't really print out anything and is called from the Windows Scheduled Task, so "CTRL+C" is not an option.
public class TestThread {
	public static void main(String[] args) {
		try {
			while (true) {
				System.out.println("Hello world!");
				Thread.sleep(30000);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Open in new window

0
Comment
Question by:killdurst
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 6

Expert Comment

by:wwnosal
ID: 22624460
Alt + Ctrl + Del

In task Manager  select this process and press End process. (It might be listed as java.exe)
0
 
LVL 1

Author Comment

by:killdurst
ID: 22624568
Thanks. That works on my PC, but on the application server, I can't find java.exe in the process list. Is there another way to see the list of running process and then kill the ones I don't want?
0
 
LVL 6

Expert Comment

by:wwnosal
ID: 22624675
On which platform this application server is running. Is it windows? Unix? Linux?

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:killdurst
ID: 22624800
Windows.
0
 
LVL 6

Accepted Solution

by:
wwnosal earned 2000 total points
ID: 22624874
tasklist.exe to list processes

taskkill.exe /PID pid_read_from_previous_command
0
 
LVL 1

Author Comment

by:killdurst
ID: 22624993
Thanks man. Going back to work in around 9 hours time. Gonna try that out. Will get back to you soon if everything works out alright.
0
 
LVL 9

Expert Comment

by:mbodewes
ID: 22626625
If you see more java or javaw commands, you might want to try and use the new jmonitor (GUI) or jps (command line) tools included in the latest JDK's. This will actually tell you what the java or javaw is doing, and you can kill the correct process using the process ID (PID) using the task manager. Always try <ctrl><break> first for command line applications, because sending a signal to an application allows it to exit more gracefully.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question