diff --git a/java/api/src/main/java/io/ray/api/BaseActorHandle.java b/java/api/src/main/java/io/ray/api/BaseActorHandle.java index 3adfdbf51..07360f723 100644 --- a/java/api/src/main/java/io/ray/api/BaseActorHandle.java +++ b/java/api/src/main/java/io/ray/api/BaseActorHandle.java @@ -14,6 +14,15 @@ public interface BaseActorHandle { */ ActorId getId(); + /** + * Kill the actor immediately. This will cause any outstanding tasks submitted to the actor to + * fail and the actor to exit in the same way as if it crashed. The killed actor will not be + * restarted anymore. + */ + default void kill() { + Ray.internal().killActor(this, true); + } + /** * Kill the actor immediately. This will cause any outstanding tasks submitted to the actor to * fail and the actor to exit in the same way as if it crashed. diff --git a/java/test/src/main/java/io/ray/test/KillActorTest.java b/java/test/src/main/java/io/ray/test/KillActorTest.java index 6e3a64391..c8ad3b8ed 100644 --- a/java/test/src/main/java/io/ray/test/KillActorTest.java +++ b/java/test/src/main/java/io/ray/test/KillActorTest.java @@ -42,6 +42,10 @@ public class KillActorTest extends BaseTest { public void kill(ActorHandle actor, boolean noRestart) { actor.kill(noRestart); } + + public void killWithoutRestart(ActorHandle actor) { + actor.kill(); + } } private static void localKill(ActorHandle actor, boolean noRestart) { @@ -87,10 +91,16 @@ public class KillActorTest extends BaseTest { public void testLocalKill() { testKillActor(KillActorTest::localKill, false); testKillActor(KillActorTest::localKill, true); + testKillActor((actorHandle, noRestart) -> actorHandle.kill(), true); } public void testRemoteKill() { testKillActor(KillActorTest::remoteKill, false); testKillActor(KillActorTest::remoteKill, true); + testKillActor((actor, noRestart) -> { + ActorHandle killer = Ray.actor(KillerActor::new).remote(); + killer.task(KillerActor::killWithoutRestart, actor).remote(); + }, true); } + }