Java program stop work

Java program stop work

By : user2956194
Date : November 22 2020, 10:54 AM
this one helps. 10mb is a very small amount of memory, and before I go any further I want to make it clear that it is not enough memory. The permanent space is taking up 55.08% of that amount. Old generation is taking up 34.90%, and the Eden space is at 12.72%. This adds up to 102.7% of the maximum heap size you've allowed, and I'm guessing that an OutOfMemoryError was thrown shortly after this reading.
code :

Share : facebook icon twitter icon
Stop external program when Java program is stopped

Stop external program when Java program is stopped

By : user3147380
Date : March 29 2020, 07:55 AM
it helps some times To trigger the shutdown, you could add a shutdown hook to your Java application. See Runtime.addShutdownHook().
To effect the shutdown, you could either communicate to the external process a request to stop gracefully, or call Process.destroy()
Java exceptions and program flow: how to know if the program will stop or continue after an exception is thrown?

Java exceptions and program flow: how to know if the program will stop or continue after an exception is thrown?

By : Anita Bahar
Date : March 29 2020, 07:55 AM
it fixes the issue It isn't executed because uncaught exceptions terminate the current thread(main thread in your case).
test() throws a RuntimeException. Surrounding test() with a try-catch would catch the exception and allow your program to continue.
code :
try {
} catch(RuntimeException e) {
    System.out.println("test() failed");
How to Stop a Running a Program Using Other Java Program

How to Stop a Running a Program Using Other Java Program

By : farheen khan
Date : March 29 2020, 07:55 AM
around this issue I'd suggest to use the following solution:
start your program with a title specified get PID of the process using "tasklist" command. A CSV parser required. There are tons of available I believe, like org.apache.commons.csv.CSVParser etc :) kill the process by "taskkill" command using PID.
code :
public static final String          NL = System.getProperty("line.separator", "\n");

public <T extends Appendable> int command(String... cmd) throws Exception {
    return command(null, cmd);

public <T extends Appendable> int command(T out, String... cmd) throws Exception {
    try {

        final ProcessBuilder pb = new ProcessBuilder(cmd);


        final Process proc = pb.start();
        final BufferedReader rd = new BufferedReader(new InputStreamReader(proc.getInputStream()));

        for (;;) {
            final String line = rd.readLine();

            if (line == null) {

            if (out != null) {

        return proc.waitFor();

    } catch (InterruptedException e) {
        throw new IOException(e);

public void startProcessWithTitle(String pathToExe, String title) throws Exception {
    command("cmd.exe", "/C", "start", '"' + pathToExe + '"', '"' + title + '"', ..cmd.params..);

public int findProcessByTitle(String title) throws Exception {

    final StringBuilder list = new StringBuilder();

    if (command(list, "tasklist", "/V", "/FO", "csv") != 0) {
        throw new RuntimeException("Cannot get tasklist. " + list.toString());

    final CSVReader csv = new CSVReader(new StringReader(list.toString()), ',', true, "WindowsOS.findProcessByTitle");
    csv.readHeaders(true); // headers

    int pidIndex = csv.getHeaderIndex("PID");
    int titleIndex = csv.getHeaderIndex("Window Title");

    while (csv.nextLine()) {
        final String ttl = csv.getString(titleIndex, true);
        if (ttl.contains(title)) {
            return csv.getInt(pidIndex);                


    return -1;

public boolean killProcess(int pid) throws Exception {
    return command("taskkill", "/T", "/F", "/PID", Integer.toString(pid)) == 0;
What's wrong with my codes? When I enter string then the program is stop working. How can I keep work the program even e

What's wrong with my codes? When I enter string then the program is stop working. How can I keep work the program even e

By : user3720952
Date : March 29 2020, 07:55 AM
will be helpful for those in need Is the problem that you want to swallow the exception and keep the program running on invalid input? If so, remove the raise. You'll also need to put the s_int checks inside the try.
code :
print ("bu program sıcaklığa göre suyun durumunu gösterir")
while True:
   s=input("lütfen sıcaklığı giriniz.çıkmak içn q ya bas")
   if s=="q":
        if s_int<0:
            print("Durum Buzdur")
        elif s_int>=100:
            print("Durum Buhar")
            print("Durum su")
   except ValueError:
        print("Lütfen sadece sayı giriniz")
Java one code to stop in a loop and not stop the entire program in eclipse

Java one code to stop in a loop and not stop the entire program in eclipse

By : Lamantenok
Date : March 29 2020, 07:55 AM
I wish this help you If you have Thread.sleep(xxx); in the current thread, then yes, it will stop the current thread for xxx seconds. Because (most likely) Thread.sleep is in the same thread that is controlling the GUI, it is pausing your code from executing, freezing your application. There are two ways you can fix this:
Create a new thread and place the timer code in there:
code :
    // Because the code is in a different thread, Thread.sleep(1000) will not pause
    // the current thread and the application will continue as normal
    Thread thread = new Thread(new Runnable() {

        int seconds = 0;

        public void run()
            while (true) {

                // wait one second
                try {
                catch (InterruptedException e) {
                // increment seconds



Timer timer = new Timer(1000, new ActionListener() {
    public void actionPerformed(ActionEvent a)
        System.out.println("Timer went off!");

// Repeat every second
Related Posts Related Posts :
  • Stream corrupted exception - invalid code type AC [java]
  • Routing Sysout values to JTextArea
  • GWT RPC serialization for Dynamic Host Page
  • Best Approch of Returning Value from 'getter' Method
  • Understanding xml schemalocation
  • Checking if a PDF is PDF/A 1-a format or not using PDFBOX in java
  • Difference Between Variable and Identifier
  • How to compute two aggregate functions with Java streams?
  • Parse the value of the json to baseadapter in android?
  • JavaFX animation on raspberry pi
  • Solve "unchecked warning" in Java avoiding @suppressWarnings
  • How to specify a new name for a file while moving it to another directory in Java?
  • Popup window not showing up with spinner item selection?
  • how to iterate through json objects in java
  • Caused by: java.lang.NoClassDefFoundError: org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor
  • Getting NoClassDefFoundError while running PMD task from Gradle
  • Matlab drag and drop file from windows explorer to figure (gui)
  • How does scala's actor model make use of C threads and native system threads?
  • Store java.util.Date as key in a Map based on reference equality instead of "value" equality
  • Error when logging into FTP from AsyncTask class using org.apache.commons.net.ftp.FTPClient
  • creating unique index in mongoDB
  • hibernate Query to find record based on substring
  • How many strings are in jvm string pool intern
  • Unable to initialize native-platform. on Jenkins
  • How to create a list of dummy files in Java?
  • Docker: Which approach is better? WAR embedded in image or base image + war?
  • java.lang.InternalError: CallerSensitive annotation expected at frame 1
  • How to write a method to read JSON files of different structures and return different POJO objects in Java?
  • Reference to Classes in Java
  • Unable to call function via companion object
  • REST: convert XML content passed with POST to a java object, attribute inside the element
  • Device not receive message from GCM
  • How to increase Openfire concurrent connection limit?
  • Android send custom parameter on AsyncTask
  • GWT - Get dom element's value from another page
  • How can i initialize an array in Java?
  • Is it possible to increase a java process's(when is running) size?
  • Getting Node Address instead of Value in Binary Search Tree
  • PdfByteContent not adding in iText pdf
  • Spring JpaRepository: delete() with subsequent save() in the same transaction
  • producer-consumer using arraydeque working only in breakpoint
  • Adding a JPanel to another JPanel
  • Comparison with operator ==, how does it work?
  • Error buildling with maven for openshift
  • What is the java equivilant to MySQL's smallint
  • proxy trouble on eclipse with https
  • Spring-Jdbc Template and Prepared statement
  • Mule - exception in Outbound endpoint Message payload is of type: byte[]
  • Modify package names for java classes generated from wsdl
  • How to download multiple images and have one progressBar using AsynTask (Android)
  • Implementing Service Provider, IdP and user in java with SAML (POC)
  • Why does my scanner repeat?
  • Can I forget ResultSetFuture in Cassandra java driver without facing memory leak?
  • XML to JAXB binding having nested elements?
  • Java: ToString() prints the same hashcode each time
  • Why am I getting a thread exception in my graphics program?
  • Can we read 4th byte from hexadecimal value?
  • How to create watermark in image just like Google maps watermarks
  • how come Thread class called inside another class?
  • AssertionError: Unexpected schema version 0: Unexpected schema version 0
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org