本文介绍了使用Java 7 Update 25的rmi线程中的AppContext为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们最近从Update 21更新到Java 7 Update 25,并且当从rmi线程调用SwingUtilities.isEventDispatchThread()时,现在遇到空指针异常,因为AppContext.getAppContext()返回null。

We recently updated to Java 7 Update 25 from Update 21 and are now experiencing a null pointer exception when SwingUtilities.isEventDispatchThread() is called from an rmi thread becuase AppContext.getAppContext() is returning null.

此错误仅出现在网站上,当我们通过IDE运行我们的应用程序时,它很好。

This error is only present from web start, when we run our application through an IDE, it is fine.

还有其他人跑了进入这个?有关AppContext的最新更新中有什么变化的想法吗?

Has anyone else ran into this? Any idea of what was changed in the latest update regarding AppContext?

似乎其他人在更新后与AppContext有一些相关的问题:

It seems others are having somewhat related issues with AppContext after the update:https://forums.oracle.com/message/11077767#11077767

推荐答案

我遇到了与Java Web Start一样运行的Java3D的问题。我找到了另一个解决方案。您必须使用runnables队列准备自己的InvokeLaterProcessor。它必须扩展Thread并获取runnables并在run方法中处理它们:

I had the same problem with Java3D running as Java Web Start. I have found another solution. You have to prepare you own InvokeLaterProcessor with queue of runnables. It must extend Thread and pick ups runnables and process them in run method:

public class InvokeLaterProcessor extends Thread {

  private BlockingQueue<Runnable> queue=new ArrayBlockingQueue<Runnable>(1);

  public InvokeLaterProcessor(String name) {
    super(name);
  }

  public void invokeLater(Runnable runnable) {
    try {
      queue.put(runnable);
    } catch (InterruptedException ex) {
      log.warn("invokeLater interrupted");
    }
  }

  public void run() {
    Runnable runnable=null;
    do {
      try {
        runnable = queue.take();
        SwingUtilities.invokeLater(runnable);
      } catch (InterruptedException ex) {
        runnable=null;
      }
    } while(runnable!=null);
  }
}

你所要做的就是在静态中创建它在主线程中创建的某些类:

Than all you have to do is create it in static of some class which is created in main thread:

static {
  invokeLaterProcessor=new InvokeLaterProcessor("MyInvokeLater");
  invokeLaterProcessor.start();
}

并按此代码处理runnables:

and process runnables by this code:

invokeLaterProcessor.invokeLater(runnable);

您不需要专有

sun.awt.SunToolkit.invokeLaterOnAppContext(evtContext, rn)

这篇关于使用Java 7 Update 25的rmi线程中的AppContext为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-16 05:37