Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into mc
[simgrid.git] / src / bindings / java / org / simgrid / msg / Task.java
index d3e2894..0ee65c4 100644 (file)
@@ -25,16 +25,10 @@ public class Task {
 
        private double messageSize;
 
-       static private Long idCpt = 0L;
-
-       private Long id;
-
        /** Default constructor (all fields to 0 or null) */
        public Task() {
                create(null, 0, 0);
                this.messageSize = 0;
-               setId(idCpt);
-               idCpt++;
        }
 
        /* *              * *
@@ -57,8 +51,6 @@ public class Task {
        public Task(String name, double flopsAmount, double bytesAmount) {
                create(name, flopsAmount, bytesAmount);
                this.messageSize = bytesAmount;
-               setId(idCpt);
-               idCpt++;
        }
        /**
         * Construct an new parallel task with the specified processing amount and amount for each host
@@ -169,17 +161,19 @@ public class Task {
        /** Cancels a task. */ 
        public native void cancel();
 
-       /** Deletes a task.
-        *
-        * @exception                   NativeException if the destruction failed.
-        */ 
-       protected void finalize() throws NativeException {
-               destroy();
+       /** Deletes a task once the garbage collector reclaims it */
+       @Override
+       protected void finalize() {
+               try {
+                       // Exceptions in finalizers lead to bad situations:
+                       // http://stackoverflow.com/questions/7644556/troubleshooting-a-java-memory-leak-finalization
+                       nativeFinalize();
+                       bind=0; // to avoid segfaults if the impossible happens yet again making this task surviving its finalize()
+               } catch (Throwable e) {
+                       e.printStackTrace();
+               }
        }
-       /**
-        * The natively implemented method to destroy a MSG task.
-        */
-       protected native void destroy();
+       protected native void nativeFinalize();
        /* *                       * *
         * * Communication-related * *
         * *                       * */
@@ -376,12 +370,4 @@ public class Task {
        public double getMessageSize() {
                return this.messageSize;
        }
-
-       public Long getId() {
-               return id;
-       }
-
-       public void setId(Long id) {
-               this.id = id;
-       }
 }