Как отправить сигнал "ctrl+c" / sigint, чтобы Gradle javaexec type type type jvm?JAVA

Программисты JAVA общаются здесь
Anonymous
Как отправить сигнал "ctrl+c" / sigint, чтобы Gradle javaexec type type type jvm?

Сообщение Anonymous »

У меня есть следующая задача Gradle < /p>

Код: Выделить всё

task bootup(type: JavaExec) {
dependsOn build
classpath = sourceSets.main.runtimeClasspath
main = 'org.example.ServerLauncher'
args 'hello'
maxHeapSize '512m'
}
и класс serverlauncher.java IS

Код: Выделить всё

package org.example;

import java.util.concurrent.CountDownLatch;

public class ServerLauncher {
private final CountDownLatch shutdownHook;
private final String[] args;

private ServerLauncher(String[] args) {
this.args = args;
this.shutdownHook = new CountDownLatch(1);
}

public static void main(String[] args) throws Exception {
new ServerLauncher(args).execute();
}

private void execute() throws Exception {
hangShutdownHook();
System.out.println("Launcher has started");
try {
shutdownHook.await();
} finally {
System.out.println("Launcher has closed");
}
}

private void hangShutdownHook() {
Thread thread = new Thread(this::triggerShutdown);
Runtime.getRuntime().addShutdownHook(thread);
}

private void triggerShutdown() {
System.out.println("Shutdown has triggered");
shutdownHook.countDown();
}
}
Когда я строю jar ./gradlew jar и запускаю java -Jar/path/to/exec В CLI я могу закрыть исполняемое исполнение с помощью Ctrl+C .

Код: Выделить всё

Launcher has started
^CShutdown has triggered
Launcher has closed
Но если я запускаю ./gradlew bootup Я не могу закрыть исполняемое изящно с помощью ctrl+c

Код: Выделить всё

> Task :bootup
Launcher has started
 91% EXECUTING [8s]
> :bootup
^C%
Как вы можете видеть triggershutdown не выполнен. Shutdownhooks? Тем не менее, я в порядке с изменением определения задачи Gradle.

Подробнее здесь: https://stackoverflow.com/questions/641 ... forked-jvm

Вернуться в «JAVA»