简体   繁体   English

Java - 当使用ForkJoinPool时,Applet在Firefox上不起作用(在Eclipse中工作时)

[英]Java - Applet doesn't work on Firefox when usign ForkJoinPool (while in Eclipse works)

when I run the following code on Eclipse (Luna, java vers=8), the code runs and pops-up the two errors messages. 当我在Eclipse上运行以下代码(Luna,java vers = 8)时,代码会运行并弹出两个错误消息。 On the other hand, when I embed the code in a html page the code shows only the first error message. 另一方面,当我将代码嵌入到html页面中时,代码仅显示第一条错误消息。 It seems that calling the ForkJoinPool class crushes the applet on firefox. 似乎调用ForkJoinPool类会破坏firefox上的applet。 Do you know why? 你知道为什么吗? Here is the code. 这是代码。

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.ForkJoinPool;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class ProvaVera extends JApplet
{
    public void start() 
    {

        SwingUtilities.invokeLater(new Runnable(){
        public void run() 
            {
                MainPanel panel = new MainPanel();      
                // Add Swing components to content pane
                Container c = getContentPane();
                c.add(panel, BorderLayout.CENTER);
            }
        });

    }

}
class MainPanel extends JPanel
{

    public MainPanel()
    {
        JLabel label1 = new JLabel("label1");
        this.add(label1);
        JButton btn1 = new JButton("button1");
        this.add(btn1);

        btn1.addActionListener  (
                new ActionListener() 
                {
                    public void actionPerformed(ActionEvent e)
                    {
                        metodo();
                    }
                }

                );
    }



    public void metodo()
    {
        JOptionPane.showMessageDialog(new JFrame(), "test1", "Dialog", JOptionPane.ERROR_MESSAGE);
        ForkJoinPool pool = new ForkJoinPool();
        JOptionPane.showMessageDialog(new JFrame(), "test2", "Dialog", JOptionPane.ERROR_MESSAGE);
    }
}

You are probably getting a security exception because ForkJoinPool requires the 'modifyThread' runtime permission. 您可能会收到安全性异常,因为ForkJoinPool需要'modifyThread'运行时权限。

When you run in Eclipse there is no security manager installed so you don't get security exceptions. 在Eclipse中运行时,没有安装安全管理器,因此您不会获得安全性异常。 When you run in a browser there is a strict security manager. 当您在浏览器中运行时,有一个严格的安全管理器。

I have enabled the Java console from the java control panel. 我已经从java控制面板启用了Java控制台。 And the error was: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "modifyThread") 错误是:java.security.AccessControlException:访问被拒绝(“java.lang.RuntimePermission”“modifyThread”)

So I went to my java.policy file located in java.home/lib/security/ and I wrote the following 所以我去了java.home / lib / security /中的java.policy文件,我写了以下内容

grant codeBase "url or file where the applet is" {
permission java.lang.RuntimePermission "modifyThread";
};

And now the applet is working. 现在applet正在运行。

Again, thank you for your support. 再次感谢您的支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM