X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b34b0ee556e0d057336cf1715f9fec0d48dd3585..c80ea3788d692dc92728cefdd199e83a93a6fa25:/src/bindings/java/org/simgrid/msg/Task.java diff --git a/src/bindings/java/org/simgrid/msg/Task.java b/src/bindings/java/org/simgrid/msg/Task.java index 95893ec91a..2b9481fff9 100644 --- a/src/bindings/java/org/simgrid/msg/Task.java +++ b/src/bindings/java/org/simgrid/msg/Task.java @@ -42,11 +42,11 @@ public class Task { * * @param flopsAmount A value of the processing amount (in flop) needed to process the task. * If 0, then it cannot be executed with the execute() method. - * This value has to be >= 0. + * This value has to be ≥ 0. * * @param bytesAmount A value of amount of data (in bytes) needed to transfert this task. * If 0, then it cannot be transfered with the get() and put() methods. - * This value has to be >= 0. + * This value has to be ≥ 0. */ public Task(String name, double flopsAmount, double bytesAmount) { create(name, flopsAmount, bytesAmount); @@ -161,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 * * * * * */ @@ -197,7 +199,7 @@ public class Task { * @throws HostFailureException * @throws TransferFailureException */ - public void send(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException { + public void send(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException, NativeException { send(mailbox, -1); } @@ -211,7 +213,7 @@ public class Task { * @throws HostFailureException * @throws TransferFailureException */ - public native void send(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException; + public native void send(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException, NativeException; /** Sends the task on the specified mailbox (capping the sending rate to \a maxrate) * @@ -361,7 +363,7 @@ public class Task { */ public static native void nativeInit(); static { - Msg.nativeInit(); + org.simgrid.NativeLib.nativeInit(); nativeInit(); }