Java (简单代码)SwingWorker死锁

Java (简单代码)SwingWorker死锁,java,multithreading,swing,deadlock,swingworker,Java,Multithreading,Swing,Deadlock,Swingworker,我正在创建一个java程序,它将打开一个启动图像,然后每隔15分钟显示一个(新的或旧的)图像,该图像是从函数CallMinutesInternational加载的。。。(在doInBackground中) 为了简单起见,此图像每隔几段时间就会更改一次 现在我有一只非常奇怪的虫子。。。。下面的代码只会在VISTA机器上死锁,但不会在我的机器上死锁,也不会在Microsoft Server 2008 SP1机器上死锁 这让我相信有些东西是我得不到的 我已排除进程()中的所有swing调用和创建。但是

我正在创建一个java程序,它将打开一个启动图像,然后每隔15分钟显示一个(新的或旧的)图像,该图像是从函数CallMinutesInternational加载的。。。(在doInBackground中)

为了简单起见,此图像每隔几段时间就会更改一次

现在我有一只非常奇怪的虫子。。。。下面的代码只会在VISTA机器上死锁,但不会在我的机器上死锁,也不会在Microsoft Server 2008 SP1机器上死锁

这让我相信有些东西是我得不到的

我已排除进程()中的所有swing调用和创建。但是,在20-50次间隔后,我的工作电脑将死锁(Vista)

如果有人能解释为什么会发生这种情况,我将不胜感激。我已经花了很多天试图修复这个简单的。。。这是一个讨厌的错误,但我无法控制它

有什么建议吗

public class GUIThreadremaster extends JComponent {



static JFrame f = new JFrame();
static JLabel label = new JLabel();
static final String version = "v.72";
static final String splashUrl = "http://s3.postimg.org/48nx9vkur/image.jpg";




public static void main(String[] args) {



            SwingUtilities.invokeLater(new Runnable() {
            public void run() {

                new GUIThreadremaster();
                n.execute();


            }});

   // A.GUIThread();

}



public static SwingWorker<Void, BufferedImage> n = new SwingWorker<Void,BufferedImage>()
        {
        //Semaphore block = new Semaphore(0);
        boolean b = false;


            @Override
            protected Void doInBackground()
                    throws Exception {
                // TODO Auto-generated method stub


                 URL url = null;
                 BufferedImage image = null;
                 String s;
                 int i = 1;

                 Thread.sleep(15000);
                while(!b)
                {


                     System.out.println(Thread.currentThread() + " " + i);
                     i++;


               s =  CallMinInternational.updateGraph(CallMinInternational.queryResultsLive(false));
                    //System.out.println("test");
                //  s = splashUrl;
                url = new URL(s);
                try {
                    image = ImageIO.read(url);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }



                //System.out.println("UPDATED : " );

                publish(image);
                 Thread.sleep(15000);
                }


                return null;

            }

            @Override
            protected void process(List<BufferedImage> chunks) 
            {
                ImageIcon tmp = new ImageIcon();
                tmp.setImage(chunks.get(chunks.size() - 1));

                JLabel labelnew = new JLabel();
                labelnew.setIcon(tmp);
                //System.out.println(Thread.currentThread());
                //System.out.println("test");
                f.getContentPane().removeAll();
                f.getContentPane().add(labelnew);
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.pack();

                f.setLocation(f.getX(), f.getY());



            }

        };

public GUIThreadremaster() {


                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (InstantiationException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (UnsupportedLookAndFeelException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                           try {
                                f.getContentPane().removeAll();


                               //String path = "http://chart.finance.yahoo.com/z?s=GOOG&t=6m&q=l";
                               // System.out.println("Get Image from " + path);
                               // URL url = new URL(path);
                                //BufferedImage image = ImageIO.read(url);
                                URL url = new URL(splashUrl);
                                BufferedImage image = ImageIO.read(url);

                                label = new JLabel(new ImageIcon(image));
                                //JFrame f = new JFrame();
                                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                f.getContentPane().add(label);
                                f.pack();
                                f.setLocation(f.getX(), f.getY());
                                f.setVisible(true);
                                f.setResizable(false);
                                f.getContentPane().repaint();
                                f.setTitle("I.O.M.S - 360 Communications " + version);

                            } catch (Exception exp) {
                                exp.printStackTrace();
                            } 




        //   n.execute();



 }
}
public类guithreadmaster扩展JComponent{
静态JFrame f=新JFrame();
静态JLabel标签=新JLabel();
静态最终字符串版本=“v.72”;
静态最终字符串splashUrl=”http://s3.postimg.org/48nx9vkur/image.jpg";
公共静态void main(字符串[]args){
SwingUtilities.invokeLater(新的Runnable(){
公开募捐{
新的GUIThreadremaster();
n、 执行();
}});
//A.GUIThread();
}
公共静态SwingWorker n=新SwingWorker()
{
//信号量块=新信号量(0);
布尔b=假;
@凌驾
受保护的Void doInBackground()
抛出异常{
//TODO自动生成的方法存根
URL=null;
BuffereImage图像=空;
字符串s;
int i=1;
睡眠(15000);
而(!b)
{
System.out.println(Thread.currentThread()+“”+i);
i++;
s=CallMinInternational.updateGraph(CallMinInternational.queryResultsLive(false));
//系统输出打印(“测试”);
//s=splashUrl;
url=新的url;
试一试{
image=ImageIO.read(url);
}捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
//System.out.println(“更新:”);
出版(图片);
睡眠(15000);
}
返回null;
}
@凌驾
受保护的无效进程(列表块)
{
ImageIcon tmp=新的ImageIcon();
setImage(chunks.get(chunks.size()-1));
JLabel labelnew=新的JLabel();
labelnew.setIcon(tmp);
//System.out.println(Thread.currentThread());
//系统输出打印(“测试”);
f、 getContentPane().removeAll();
f、 getContentPane().add(labelnew);
f、 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f、 包装();
f、 设置位置(f.getX(),f.getY());
}
};
公共吉他手(){
试一试{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(classnotfounde异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}捕获(实例化异常e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}捕获(非法访问例外e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}捕获(无支持的LookandFeelException e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
试一试{
f、 getContentPane().removeAll();
//字符串路径=”http://chart.finance.yahoo.com/z?s=GOOG&t=6m&q=l";
//System.out.println(“从“+路径获取图像”);
//URL=新URL(路径);
//BuffereImage image=ImageIO.read(url);
URL URL=新URL(splashUrl);
BuffereImage image=ImageIO.read(url);
标签=新JLabel(新图像图标(图像));
//JFrame f=新的JFrame();
f、 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f、 getContentPane().add(标签);
f、 包装();
f、 设置位置(f.getX(),f.getY());
f、 setVisible(真);
f、 可设置大小(假);
f、 getContentPane().repaint();
f、 setTitle(“I.O.M.S-360通信”+版本);
}捕获(异常扩展){
exp.printStackTrace();
} 
//n.执行();
}
}
新代码:(垃圾神)

public类guithreadmaster扩展JComponent{
静态JFrame f=新JFrame();
静态JLabel标签=新JLabel();
静态最终字符串版本=“v.75”;
静态最终字符串splashUrl=”http://s3.postimg.org/48nx9vkur/image.jpg";
公共静态void main(字符串[]args){
SwingUtilities.invokeLater(新的Runnable(){
公开募捐{
新的GUIThreadremaster();
n、 执行();
}});
//A.GUIThread();
}
公共静态SwingWorker n=新SwingWorker()
{
//信号量集团
public class GUIThreadremaster extends JComponent {



static JFrame f = new JFrame();
static JLabel label = new JLabel();
static final String version = "v.75";
static final String splashUrl = "http://s3.postimg.org/48nx9vkur/image.jpg";




public static void main(String[] args) {



            SwingUtilities.invokeLater(new Runnable() {
            public void run() {

                new GUIThreadremaster();
                n.execute();


            }});

   // A.GUIThread();

}



public static SwingWorker<Void, BufferedImage> n = new SwingWorker<Void,BufferedImage>()
        {
        //Semaphore block = new Semaphore(0);
        boolean b = false;


            @Override
            protected Void doInBackground()
                    throws Exception {
                // TODO Auto-generated method stub


                 URL url = null;
                 BufferedImage image = null;
                 String s;
                 int i = 1;

                 Thread.sleep(15000);
                while(!b)
                {


                     System.out.println(Thread.currentThread() + " " + i);
                     i++;


                 s =  CallMinInternational.updateGraph(CallMinInternational.queryResultsLive(false));
                    //System.out.println("test");
                //  s = splashUrl;
                url = new URL(s);
                try {
                    image = ImageIO.read(url);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }



                //System.out.println("UPDATED : " );

                publish(image);
                 Thread.sleep(15000);
                }


                return null;

            }

            @Override
            protected void process(List<BufferedImage> chunks) 
            {
                ImageIcon tmp = new ImageIcon();
                tmp.setImage(chunks.get(chunks.size() - 1));


                label.setIcon(tmp);
                //System.out.println(Thread.currentThread());
                //System.out.println("test");
                f.pack();




            }

        };

public GUIThreadremaster() {


                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (InstantiationException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (UnsupportedLookAndFeelException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                           try {
                                f.getContentPane().removeAll();


                               //String path = "http://chart.finance.yahoo.com/z?s=GOOG&t=6m&q=l";
                               // System.out.println("Get Image from " + path);
                               // URL url = new URL(path);
                                //BufferedImage image = ImageIO.read(url);
                                URL url = new URL(splashUrl);
                                BufferedImage image = ImageIO.read(url);

                                label = new JLabel(new ImageIcon(image));
                                //JFrame f = new JFrame();
                                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                f.getContentPane().add(label);
                                f.pack();
                                f.setLocation(f.getX(), f.getY());
                                f.setVisible(true);
                                f.setResizable(false);
                                f.getContentPane().repaint();
                                f.setTitle("I.O.M.S - 360 Communications " + version);

                            } catch (Exception exp) {
                                exp.printStackTrace();
                            } 




        //   n.execute();



}
}