Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
java: obey to sonar, use nio.file.delete for better error messages
[simgrid.git] / src / bindings / java / org / simgrid / msg / Process.java
index 80c31a7..cfbc5da 100644 (file)
@@ -1,12 +1,12 @@
-/* Copyright (c) 2006-2018. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2006-2019. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 package org.simgrid.msg;
 
-import java.util.Arrays;
 import java.util.ArrayList;
+import java.util.Arrays;
 
 /**
  * A process may be defined as a code, with some private data, executing
@@ -147,11 +147,8 @@ public abstract class Process implements Runnable {
        
        /**
         * This method kills all running process of the simulation.
-        *
-        * @return                              The function returns the PID of the next created process.
-        *                      
         */
-       public static native int killAll();
+       public static native void killAll();
 
        /** Simply kills the receiving process.
         *
@@ -256,8 +253,8 @@ public abstract class Process implements Runnable {
        public native void migrate(Host host);  
        /**
         * Makes the current process sleep until millis milliseconds have elapsed.
-        * You should note that unlike "waitFor" which takes seconds, this method takes milliseconds.
-        * FIXME: Not optimal, maybe we should have two native functions.
+        * You should note that unlike "waitFor" which takes seconds (as usual in SimGrid), this method takes milliseconds (as usual for sleep() in Java).
+        * 
         * @param millis the length of time to sleep in milliseconds.
         */
        public static void sleep(long millis) throws HostFailureException  {
@@ -302,9 +299,7 @@ public abstract class Process implements Runnable {
                        Msg.info("Unexpected behavior. Stopping now");
                        System.exit(1);
                }
-               catch(ProcessKilledError pk) {
-                       /* The process was killed before its end. With a kill() or something. */
-               }       
+               /* Let the ProcessKilledError (that we'd get if the process is forcefully killed) flow back to the caller */
        }
 
        /**
@@ -334,4 +329,10 @@ public abstract class Process implements Runnable {
         */
        public static native int getCount();
 
+        public static void debugAllThreads() {
+           // Search remaining threads that are not main nor daemon
+            for (Thread t : Thread.getAllStackTraces().keySet())
+                if (! t.isDaemon() && !t.getName().equals("main"))
+                    System.err.println("Thread "+t.getName()+" is still running! Please report that bug");
+        }
 }