为什么java.util.concurrent.FutureTask无法序列化 [英] Why is java.util.concurrent.FutureTask not serializable

查看:758
本文介绍了为什么java.util.concurrent.FutureTask无法序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用Apache Wicket.我有一些REST调用,每个调用需要几秒钟. Wicket只允许ajax同步调用,因此我试图使用Future和Callable.

I am currently using Apache Wicket. I have some REST calls which take a few seconds each. Wicket allows ajax calls synchronously only, so I was trying to use Future and Callable.

这是我课程的一部分:

public abstract class GetPrices extends AbstractAjaxTimerBehavior {
        private static final long serialVersionUID = 1L;    
        private List<Future<List<Result>>> list;

        public GetPrices(Duration updateInterval, List<Callable> priceCalls) {
           super(updateInterval);
           list = new ArrayList<Future<List<Result>>>();

           ExecutorService executor = Executors.newFixedThreadPool(priceCalls.size());
           for(Callable callable : priceCalls) {
               list.add(executor.submit(callable));
           }
           executor.shutdown();
        }

        @Override
        protected void onTimer(AjaxRequestTarget target) {
            while(list.hasNext()) {
                Future<List<Result>> future = listIterator.next();
                if(future.isDone()) {
                    List<Result> data = future.get();
                    //Process data
                }
            }
        }
    //Error handling etc
}

List<Callable> priceCalls包含对相应价格调用的方法调用

The List<Callable> priceCalls contains the method calls to the appropriate price calls

我收到对象类型不可序列化!针对java.util.concurrent.FutureTask列表字段

I receive The object type is not Serializable! against java.util.concurrent.FutureTask list field

我假设我应该对此进行不同的设计.任何人都可以提供有关如何完成此操作的想法吗?

I am assuming I should design this differently. Could any provide any thoughts on how this should be done?

如果有帮助,我正在使用Spring

I am using Spring if that helps

推荐答案

我最终使用了Spring的Async和AjaxLazyLoadPanel

I ended up using Spring's Async and AjaxLazyLoadPanel

在此处查看更多信息: http://apache-wicket.1842946.n4 .nabble.com/AjaxLazyLoadPanel-loading-asynchronously-td4664035.html#a4665188

See more info here: http://apache-wicket.1842946.n4.nabble.com/AjaxLazyLoadPanel-loading-asynchronously-td4664035.html#a4665188

这篇关于为什么java.util.concurrent.FutureTask无法序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆