【问题标题】:javafx akka dispatcher leaksjavafx akka调度程序泄漏
【发布时间】:2014-09-04 08:11:54
【问题描述】:

我已经创建了一个执行器:

public class GUIExecutorService extends AbstractExecutorService {

@Override
public void shutdown() {

}

@Override
public List<Runnable> shutdownNow() {
    return new ArrayList<>();
}

@Override
public boolean isShutdown() {
    return false;
}

@Override
public boolean isTerminated() {
    return false;
}

@Override
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
    return true;
}

@Override
public void execute(Runnable command) {
    Platform.runLater(command);
}
}

和配置器:

public class JavaFXEventThreadExecutorServiceConfigurator extends ExecutorServiceConfigurator {

public JavaFXEventThreadExecutorServiceConfigurator(Config config, DispatcherPrerequisites prerequisites) {
    super(config, prerequisites);
}

@Override
public ExecutorServiceFactory createExecutorServiceFactory(String id, ThreadFactory threadFactory) {
    return () -> new GUIExecutorService(); 
}    
}

我确实使用过它:

this.navigatorActor = getContext().actorOf(new Props(() -> new NavigatorActor(stage)).withDispatcher("javafx-dispatcher"), "navigator" );

但是一旦我想在应用程序中停止使用:

actorSystem.shutdown();

我的程序仍在执行。

使用上次关闭我希望它应该关闭所有演员系统。

演员没有终止。

我的代码有什么问题?

【问题讨论】:

    标签: javafx akka actor


    【解决方案1】:

    您需要将 return bool 从 true 更改为 false。

    @Override
    public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
        return false;
    }
    

    【讨论】:

    • 不起作用。我只是把这个库和所有东西都扔掉了。我很高兴。
    【解决方案2】:

    您应该进行堆栈跟踪 (jstack PID) 或使用分析器来查看哪个线程池仍处于活动状态并正在运行。

    【讨论】:

    • 谢谢 Knrad,但我真的不明白它打印了什么:
    • 如我所见:MapReduceApp-akka.actor.default-dispatcher-5 正在运行,NapReduceApp-scheduler-1 正在运行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-20
    • 2013-08-16
    • 2016-03-07
    • 2015-04-04
    相关资源
    最近更新 更多