Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rename examples: slave -> worker.
[simgrid.git] / src / bindings / java / org / simgrid / msg / Process.java
index 7cfebdb..d8f1f3b 100644 (file)
@@ -1,12 +1,12 @@
-/* Copyright (c) 2006-2018. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2006-2020. 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
@@ -14,12 +14,12 @@ import java.util.ArrayList;
  * declared in the deployment file (XML format).
  * To create your own process you must inherit your own process from this
  * class and override the method "main()". For example if you want to use
- * a process named Slave proceed as it :
+ * a process named Worker proceed as it :
  *
  * (1) import the class Process of the package simgrid.msg
  * import simgrid.msg.Process;
  *
- * public class Slave extends simgrid.msg.Process {
+ * public class Worker extends simgrid.msg.Process {
  *
  *  (2) Override the method function
  *
@@ -30,9 +30,9 @@ import java.util.ArrayList;
  *  \endverbatim
  * }
  * The name of your process must be declared in the deployment file of your simulation.
- * For the example, for the previous process Slave this file must contains a line :
- * <process host="Maxims" function="Slave"/>, where Maxims is the host of the process
- * Slave. All the process of your simulation are automatically launched and managed by Msg.
+ * For the example, for the previous process Worker this file must contains a line :
+ * <process host="Maxims" function="Worker"/>, where Maxims is the host of the process
+ * Worker. All the process of your simulation are automatically launched and managed by Msg.
  * A process use tasks to simulate communications or computations with another process.
  * For more information see Task. For more information on host concept
  * see Host.
@@ -253,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  {
@@ -299,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 */
        }
 
        /**
@@ -331,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");
+        }
 }