This discussion is archived
1 2 Previous Next 23 Replies Latest reply: May 17, 2013 5:03 AM by mKorbel RSS

App works on java6 but not on java 7

1008584 Newbie
Currently Being Moderated
Hello reader,

I am creating a Java swing application - the animation of sorting and searching algorithms. I wrote the code with JDeveloper 11g release2, witch by default uses jdk 1.6, the app worked great, but after deployment i try to run it on my computer witch has jdk 1.7 and the app freezes at random moments and does not recover. I tryed out diferent pc's and opperating systems on everyone the app works great with java 6 but gets stuck if launched with java 7. I tryed to debugg it but the debugger freezes to like the app and does not unfreeze till i shut it down with windows task manager.

I managed to trace that the app freezes at the method - descriptionTA.setText(text) (the last method of the class below) when trying to set the text, sometimes it sets it correctly, but most times everything jsut stops with no error message or other life signals.

This is the class in witch the problem occurs.
package graphics;

import animatedalgorithms.MasterFrame;
import animatedalgorithms.sorting.SortAnimationComponent;
import helperclasses.ApplicationConstants;
import helperclasses.RenderedJLabel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.TreeMap;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTextArea;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;


public class SortAnimationPanel extends JPanel {

    private static final int DESCENDING_EELMENT_ORDER = 0;
    private static final int ASCENDING_ELEMEMENT_ORDER = 1;
    private static final int RANDOM_ELEMENT_ORDER = 2;

    private MasterFrame frame;
    private SortAnimationComponent comp;
    private RenderedJLabel h1;
    private JSlider algSlider;
    private JSlider animSlider;
    BackButtonComponent backBtn;
    private int elmOrder;
    private JTextArea descriptionTA ;
    

    public SortAnimationPanel(MasterFrame frame) {
        elmOrder = RANDOM_ELEMENT_ORDER;
        this.setBorder(new LineBorder(Color.black));
        this.frame = frame;
        this.setLayout(new BorderLayout());

        h1 = new RenderedJLabel("");
        h1.setFont(new Font("Segoe UI Semibold", Font.PLAIN, 20));
        h1.setForeground(Color.white);

        createControls();
    }

    public void createControls() {
        // Header
        JPanel header = new JPanel();
        header.setLayout(new BorderLayout());
        header.setBackground(new Color(30, 30, 30));
        header.setBorder(new EmptyBorder(0, 10, 5, 5));
        header.setForeground(Color.WHITE);
        header.add(h1, BorderLayout.CENTER);

        JPanel aboutBtn = new JPanel();
        aboutBtn.setName("aboutPanel");
        aboutBtn.setBackground(Color.BLACK);

        final RenderedJLabel aboutLabel = new RenderedJLabel("Apie algoritmą");
        aboutLabel.setForeground(Color.WHITE);
        aboutLabel.setFont(new Font("Arial", Font.BOLD, 12));
        aboutBtn.add(aboutLabel);
        
        header.add(aboutBtn, BorderLayout.EAST);
        add(header, BorderLayout.NORTH);        
        
        //Bottom controls
        JButton btn = new JButton("Iš naujo");
        btn.setName("replay");
        JButton btnPlay = new JButton("Rikiuoti");
        btnPlay.setName("play");
        JButton btnPause = new JButton("Pauzė");
        btnPause.setName("pause");
        JButton btnStep = new JButton("Žingsnis");
        btnStep.setName("step");
        backBtn = new BackButtonComponent();

        JPanel controls = new JPanel();
        controls.setLayout(new BoxLayout(controls, BoxLayout.X_AXIS));
        controls.setBackground(Color.WHITE);
        controls.add(btn);
        controls.add(btnPlay);
        controls.add(btnPause);
        controls.add(btnStep);
        controls.add(Box.createHorizontalStrut(10));

        Border empty = BorderFactory.createEmptyBorder(10, 10, 30, 10);
        controls.setBorder(empty);

        JPanel labels = new JPanel();
        labels.setLayout(new BoxLayout(labels, BoxLayout.Y_AXIS));
        labels.add(new JLabel("Algoritmo greitis: "));
        labels.add(new JLabel("Animacijos greitis: "));
        labels.setBackground(Color.WHITE);
        controls.add(labels);

        JPanel sliders = new JPanel();
        sliders.setBackground(Color.WHITE);
        sliders.setLayout(new BoxLayout(sliders, BoxLayout.Y_AXIS));
        algSlider = new JSlider(JSlider.HORIZONTAL, 100, 10000, 10000 - ApplicationConstants.DEFAULT_ALGORITHM_DELAY);
        algSlider.setBackground(Color.WHITE);
        algSlider.setMajorTickSpacing(2000);
        algSlider.setMinorTickSpacing(100);

        animSlider = new JSlider(JSlider.HORIZONTAL, 0, 20, 10);
        animSlider.setMajorTickSpacing(10);
        animSlider.setBackground(Color.WHITE);
        animSlider.setMinorTickSpacing(2);
        sliders.add(algSlider);
        sliders.add(animSlider);
        controls.add(Box.createHorizontalStrut(10));
        controls.add(sliders);

        class ButtonListener implements ActionListener {
            @Override
            public void actionPerformed(ActionEvent e) {
                JButton eventObj = (JButton)e.getSource();
                if (eventObj.getName().equalsIgnoreCase("play")) {
                    comp.setToPlay();
                } else if (eventObj.getName().equalsIgnoreCase("pause")) {
                    comp.setToPause();
                } else if (eventObj.getName().equalsIgnoreCase("replay")) {
                    resetControls();
                    switch (elmOrder) {
                    case RANDOM_ELEMENT_ORDER:
                        comp.generateRandomArray();
                        break;
                    case ASCENDING_ELEMEMENT_ORDER:
                        comp.generateAscendingArray();
                        break;
                    case DESCENDING_EELMENT_ORDER:
                        comp.generateDescendingArray();
                        break;
                    }
                    comp.resetSorter();
                    comp.startAnimation();
                } else if (eventObj.getName().equalsIgnoreCase("step")) {
                    comp.step();
                }
            }
        }

        class CustomMouseListener implements MouseListener {
            boolean pressed = false;

            @Override
            public void mouseClicked(MouseEvent e) {
            }

            @Override
            public void mousePressed(MouseEvent e) {
                pressed = true;
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                if (pressed) {
                    if (e.getSource() instanceof JPanel) {
                        JFrame aboutFrame = new DescriptionFrame(comp.getAlgorithmNum());
                    } else {
                        comp.stopThread();
                        frame.setVisibleCard(MasterFrame.MENU_WINDOW);
                    }
                }
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                if (e.getSource() instanceof JPanel) {
                    JPanel p = (JPanel) e.getSource();
                    p.setBackground(Color.WHITE);
                    aboutLabel.setForeground(Color.black);
                } else {
                    BackButtonComponent comp = (BackButtonComponent)e.getSource();
                    comp.setCompColor(Color.lightGray);
                    comp.repaint();
                }
            }

            @Override
            public void mouseExited(MouseEvent e) {
                if (e.getSource() instanceof JPanel) {
                    JPanel p = (JPanel) e.getSource();
                    p.setBackground(Color.black);
                    aboutLabel.setForeground(Color.white);
                } else {
                    BackButtonComponent comp = (BackButtonComponent)e.getSource();
                    comp.setCompColor(Color.GRAY);
                    comp.repaint();
                    pressed = false;
                }
            }
        }


        class SliderListener implements ChangeListener {

            @Override
            public void stateChanged(ChangeEvent e) {
                JSlider source = (JSlider)e.getSource();
                if (!source.getValueIsAdjusting()) {
                    if (source.getMaximum() == 20) {
                        comp.setAnimationDelay(source.getMaximum() - source.getValue());
                    } else {
                        comp.setAlgorithmStepDelay(source.getMaximum() - source.getValue());
                    }
                }
            }
        }

        ActionListener btnListener = new ButtonListener();
        btn.addActionListener(btnListener);
        btnPlay.addActionListener(btnListener);
        btnStep.addActionListener(btnListener);
        btnPause.addActionListener(btnListener);
        
        CustomMouseListener l = new CustomMouseListener();
        backBtn.addMouseListener(l);
        aboutBtn.addMouseListener(l);        
        
        ChangeListener sliderListener = new SliderListener();
        algSlider.addChangeListener(sliderListener);
        animSlider.addChangeListener(sliderListener);

        add(controls, BorderLayout.SOUTH);

    }

    public void createLeftMenu() {

    }

    public void resetControls() {
        algSlider.setValue(algSlider.getMaximum() - ApplicationConstants.DEFAULT_ALGORITHM_DELAY);
        animSlider.setValue(animSlider.getMaximum() - ApplicationConstants.DEFAULT_ANIMATION_DELAY);
    }

    public void loadAlgorithm(int sorterNum) {
        resetControls();

        JPanel sortPanel = new JPanel();
        sortPanel.setBackground(Color.WHITE);

        descriptionTA = new JTextArea();
        descriptionTA.setSelectionColor(Color.BLACK);
        descriptionTA.setFocusable(false);
        descriptionTA.setEnabled(true);
        descriptionTA.setRows(5);
        descriptionTA.setColumns(10);
        descriptionTA.setFont(new Font("Arial", Font.BOLD, 12));
        descriptionTA.setWrapStyleWord(true);
        descriptionTA.setLineWrap(true);
        TitledBorder title = BorderFactory.createTitledBorder("Aprašymas");
        descriptionTA.setBorder(title);

        HistoryComponent hist = new HistoryComponent(new TreeMap<String, Color>(), 30);
        TreeMap<String, Color> map = new TreeMap<String, Color>();
        switch (sorterNum) {
            case ApplicationConstants.SELECTION_SORT_NUM:
            h1.setText("Išrinkimo rikiavimo algoritmas");
            map.put("- Mažiausias elementas", ApplicationConstants.IMPORTANT_ELEMENT_COLOR);
            map.put("- Pasirinktas elementas", ApplicationConstants.SELECTED_ELEMENT_COLOR);
            map.put("- Neutralus elementas", ApplicationConstants.NEUTRAL_ELEMENT_COLOR);
            map.put("- Surikiuotas masyvas", ApplicationConstants.SORTED_ELEMENT_COLOR);
            hist.setMap(map);
            hist.repaint();
            comp = new SortAnimationComponent(ApplicationConstants.SELECTION_SORT_NUM, this);
            comp.setToPause();
            comp.startAnimation();
            break;
            case ApplicationConstants.BUBBLE_SORT_NUM:
            h1.setText("Burbulo rikiavimo algoritmas");
            map.put("- Pasirinktas elementas", ApplicationConstants.SELECTED_ELEMENT_COLOR);
            map.put("- Neutralus elementas", ApplicationConstants.NEUTRAL_ELEMENT_COLOR);
            hist.setMap(map);
            hist.repaint();
            comp = new SortAnimationComponent(ApplicationConstants.BUBBLE_SORT_NUM, this);
            comp.setToPause();
            comp.startAnimation();
            break;
            case ApplicationConstants.INSERTION_SORT_NUM:
            h1.setText("Įterpimo rikiavimo algoritmas");
            map.put("- Surikiuotas masyvas", ApplicationConstants.SORTED_ELEMENT_COLOR);
            map.put("- Pasirinktas elementas", ApplicationConstants.SELECTED_ELEMENT_COLOR);
            map.put("- Neutralus elementas", ApplicationConstants.NEUTRAL_ELEMENT_COLOR);
            hist.setMap(map);
            hist.repaint();
            comp = new SortAnimationComponent(ApplicationConstants.INSERTION_SORT_NUM, this);
            comp.setToPause();
            comp.startAnimation();
            break;
            case ApplicationConstants.QUICK_SORT_NUM:
            h1.setText("Greitojo rikiavimo algoritmas");
            map.put("- Vidurio taškas ", ApplicationConstants.IMPORTANT_ELEMENT_COLOR);
            map.put("- Neutralus elementas", ApplicationConstants.NEUTRAL_ELEMENT_COLOR);
            map.put("- Neaktyvus elementas", ApplicationConstants.INACTIVE_ELEMENT_COLOR);
            hist.setMap(map);
            hist.repaint();
            comp = new SortAnimationComponent(ApplicationConstants.QUICK_SORT_NUM, this);
            comp.setToPause();
            comp.startAnimation();
            break;
            case ApplicationConstants.MERGE_SORT_NUM:
            h1.setText("Suliejimo rikiavimo algoritmas");
            map.put("- Neutralus elementas", ApplicationConstants.NEUTRAL_ELEMENT_COLOR);
            map.put("- Neaktyvus elementas", ApplicationConstants.INACTIVE_ELEMENT_COLOR);
            hist.setMap(map);
            hist.repaint();
            comp = new SortAnimationComponent(ApplicationConstants.MERGE_SORT_NUM, this);
            comp.setToPause();
            comp.startAnimation();
            break;
        default:
            h1.setText("Išrinkimo rikiavimo algoritmas");
            map.put("- Mažiausias elementas", ApplicationConstants.IMPORTANT_ELEMENT_COLOR);
            map.put("- Pasirinktas elementas", ApplicationConstants.SELECTED_ELEMENT_COLOR);
            map.put("- Neutralus elementas", ApplicationConstants.NEUTRAL_ELEMENT_COLOR);
            hist.setMap(map);
            hist.repaint();
            comp = new SortAnimationComponent(ApplicationConstants.SELECTION_SORT_NUM, this);
            comp.setToPause();
            comp.startAnimation();
            break;
        }

        JPanel leftPanel = new JPanel();
        leftPanel.setLayout(new BorderLayout());
        leftPanel.setBackground(Color.WHITE);
        JPanel spacer = new JPanel();
        spacer.setBackground(Color.white);
        spacer.setLayout(new BoxLayout(spacer, BoxLayout.X_AXIS));
        spacer.add(backBtn);
        spacer.add(Box.createHorizontalStrut(120));
        leftPanel.add(spacer, BorderLayout.NORTH);

        JPanel elmOrderPanel = new JPanel();
        elmOrderPanel.setLayout(new BoxLayout(elmOrderPanel, BoxLayout.Y_AXIS));
        elmOrderPanel.setBorder(BorderFactory.createTitledBorder("Elementų išdėstymas"));
        JButton ascBtn = new JButton("Didėjimo tvarka");
        ascBtn.setName("ascBtn");
        JButton descBtn = new JButton("Mažėjimo tvarka");
        descBtn.setName("descBtn");
        JButton randBtn = new JButton("Atsitiktine tvarka");
        randBtn.setName("randBtn");
        elmOrderPanel.add(ascBtn);
        elmOrderPanel.add(descBtn);
        elmOrderPanel.add(randBtn);
        elmOrderPanel.setBackground(Color.WHITE);
        leftPanel.add(elmOrderPanel, BorderLayout.SOUTH);

        TitledBorder colorBorder = BorderFactory.createTitledBorder("Spalvų reikšmės");
        hist.setBorder(colorBorder);
        leftPanel.add(hist, BorderLayout.CENTER);

        class ButtonListener implements ActionListener {
            @Override
            public void actionPerformed(ActionEvent e) {
                JButton eventObj = (JButton)e.getSource();
                if (eventObj.getName().equalsIgnoreCase("randBtn")) {
                    resetControls();
                    comp.generateRandomArray();
                    comp.resetSorter();
                    comp.startAnimation();
                    elmOrder = RANDOM_ELEMENT_ORDER;
                } else if (eventObj.getName().equalsIgnoreCase("descBtn")) {
                    resetControls();
                    comp.generateDescendingArray();
                    comp.resetSorter();
                    comp.startAnimation();
                    elmOrder = DESCENDING_EELMENT_ORDER;
                } else if (eventObj.getName().equalsIgnoreCase("ascBtn")) {
                    resetControls();
                    comp.generateAscendingArray();
                    comp.resetSorter();
                    comp.startAnimation();
                    elmOrder = ASCENDING_ELEMEMENT_ORDER;
                }
            }
        }
        ButtonListener l = new ButtonListener();
        ascBtn.addActionListener(l);
        descBtn.addActionListener(l);
        randBtn.addActionListener(l);

        sortPanel.setLayout(new BorderLayout());
        sortPanel.add(comp, BorderLayout.CENTER);
        sortPanel.add(descriptionTA, BorderLayout.SOUTH);
        sortPanel.add(leftPanel, BorderLayout.WEST);
        add(sortPanel, BorderLayout.CENTER);
        this.updateUI();
    }
    
    public void setDescriptionText(String text){
        
        descriptionTA.setText(text);
       
    }
}
The setDescriptionText gets called from a nother thread that manages the animation in the panel above the JtextArea and sets the text in it.

The weird thing to me is that it works perfect with versions older than java 7.

If you need more code to detect the problem please let me know.
  • 1. Re: App works on java6 but not on java 7
    jtahlborn Expert
    Currently Being Moderated
    1005581 wrote:
    The setDescriptionText gets called from a nother thread that manages the animation in the panel above the JtextArea and sets the text in it.
    swing/awt ui code should never be called from a different thread. this is the first rule of java ui programming.
    If you need more code to detect the problem please let me know.
    my guess is that your problems lie in the code running on the other thread.
  • 2. Re: App works on java6 but not on java 7
    abillconsl Explorer
    Currently Being Moderated
    Interestingly, I've just done a lot of searching under such topics as:

    awt event
    awt
    awt exent dispatch
    etc

    And I can't find any tutorials that specifically target awt and event handling with threads. The Oracle java tutorial has nothing on awt anymore.
  • 3. Re: App works on java6 but not on java 7
    rp0428 Guru
    Currently Being Moderated
    >
    And I can't find any tutorials that specifically target awt and event handling with threads. The Oracle java tutorial has nothing on awt anymore.
    >
    Did you look at these?

    Concurrency in Swing: http://docs.oracle.com/javase/tutorial/uiswing/concurrency/
    AWT Tutorials and Programmer's Guides: http://docs.oracle.com/javase/6/docs/technotes/guides/awt/
  • 4. Re: App works on java6 but not on java 7
    abillconsl Explorer
    Currently Being Moderated
    Yes. They don't go into any real detail with respect to the issue pointed out. Yes they talk about the event dispatch thread, but it's all concerning swing.

    What I wanted to read about was what the tutorial said about event programming with AWT.

    Now it could be surmised that you just do the same thing as with swing. However, all the "special" programming concerning the event dispatch thread, beginning with the SwingWorker class that was developed separately some 10 years ago or so, and that has now been replaced with the new classes within the JDK, was done with swing in mind. When I started programming in Java, way back when, there was no talk about such things for AWT, before swing was introduced. At least, that's how I remember it.

    In other words I was looking for history - I wanted to see if I remembered or mis-remembered. And I could not find anything on it.
  • 5. Re: App works on java6 but not on java 7
    1008584 Newbie
    Currently Being Moderated
    I fugured out the problem. It really was in this class and it is because I call descriptionTA.setText() from a nother threat, not the EDT.

    Changed the method to :
    public void setDescriptionText(String text){      
        final String t = text; // final so I can use it an inner class.
    
        SwingUtilities.invokeLater(new Runnable() {
        public void run() {    
          descriptionTA.setText(t);
        }
    });
    }
    and it toks great.

    Ofcourse I didn't find out exactly why the code worked only on java versions prior to 7 and with 7 it works just a few random times, but the app works now.

    Thank you all for replies :)

    Edited by: Gerbiamas on 2013.5.13 14.32
  • 6. Re: App works on java6 but not on java 7
    gimbal2 Guru
    Currently Being Moderated
    Gerbiamas wrote:
    Ofcourse I didn't find out exactly why the code worked only on java versions prior to 7 and with 7 it works just a few random times, but the app works now.
    Luck. Swing has remained mostly unchanged in Java 7 (and will continue to remain unchanged due to the existence of JavaFX). There is nothing better to spot the hidden errors in your application than a nice runtime update, plenty of people then fall into the "but it worked in version XX!" trap.
  • 7. Re: App works on java6 but not on java 7
    jtahlborn Expert
    Currently Being Moderated
    gimbal2 wrote:
    Gerbiamas wrote:
    Ofcourse I didn't find out exactly why the code worked only on java versions prior to 7 and with 7 it works just a few random times, but the app works now.
    Luck. Swing has remained mostly unchanged in Java 7 (and will continue to remain unchanged due to the existence of JavaFX). There is nothing better to spot the hidden errors in your application than a nice runtime update, plenty of people then fall into the "but it worked in version XX!" trap.
    ah the joys of undefined behavior. sometimes it works, sometimes it doesn't.
  • 8. Re: App works on java6 but not on java 7
    mKorbel Explorer
    Currently Being Moderated
    @gimbal2

    - all (maybe almost of) Thread safe methods in Java6 (setText(), append(), etc ...) aren't Thread safe in Java7, only description in concrete API

    - descriptions about was lost in big clean_up on official Oracle tutorial (incl. part of code examples from Sun times)
  • 9. Re: App works on java6 but not on java 7
    abillconsl Explorer
    Currently Being Moderated
    mKorbel wrote:
    @gimbal2

    - all (maybe almost of) Thread safe methods in Java6 (setText(), append(), etc ...) aren't Thread safe in Java7, only description in concrete API

    - descriptions about was lost in big clean_up on official Oracle tutorial (incl. part of code examples from Sun times)
    So Oracle thinks they understand Java better than Sun did? :o?
  • 10. Re: App works on java6 but not on java 7
    gimbal2 Guru
    Currently Being Moderated
    Swing is and never was thread safe and has always been advertised as such, even if under the hood it just happened to be in some cases/implementations.

    This again hooks into the fact that Oracle does not seem to care about backwards compatibility or communication though and it is starting to royally annoy me. Okay perhaps the code wasn't exactly right even for Java 6 because it assumed thread-safety, but when changes are handled like this even people who have worked with Swing for yonks are caught off-guard. What are we supposed to do? Compare the code of the runtime with each new release of Java just to stay up to date!?
  • 11. Re: App works on java6 but not on java 7
    abillconsl Explorer
    Currently Being Moderated
    gimbal2 wrote:
    Swing is and never was thread safe and has always been advertised as such, even if under the hood it just happened to be in some cases/implementations.
    Oh I know! However, what I meant in my previous-previous comment was that, before swing - or early on with swing because swing was sooooooo slow at first (partly because our PCs were so comparitively slow) I did my GUIs mostly in AWT. I always just did background work from any old 'other' Thread and updated the GUIs from there - it always worked and still does. At some point in time, though, apparently the thinking on this has changed. If I was wrong all along, then I was wrong all along - certainly would not be the first time. But I never read differently and I was trying to see when and why that has changed and could not locate any authoritive write up on the subject. Note that I am only talking about AWT.
    This again hooks into the fact that Oracle does not seem to care about backwards compatibility or communication though and it is starting to royally annoy me. Okay perhaps the code wasn't exactly right even for Java 6 because it assumed thread-safety, but when changes are handled like this even people who have worked with Swing for yonks are caught off-guard. What are we supposed to do? Compare the code of the runtime with each new release of Java just to stay up to date!?
    Each time there is an update now it seems something breaks ... or at least does not work just the same. There's always been some of that, but I do think it's worse. On my mind is all the talk about security issues for Applets ... but that's just as much (or in fact mostly) hackers turning their attention to it as it is the fault of Oracle probably ... though I say that not knowing if hackers were working on this for a long or a short time, and not knowing either any of the internal changes that lead to the problems.
  • 12. Re: App works on java6 but not on java 7
    jtahlborn Expert
    Currently Being Moderated
    abillconsl wrote:
    gimbal2 wrote:
    Swing is and never was thread safe and has always been advertised as such, even if under the hood it just happened to be in some cases/implementations.
    Oh I know! However, what I meant in my previous-previous comment was that, before swing - or early on with swing because swing was sooooooo slow at first (partly because our PCs were so comparitively slow) I did my GUIs mostly in AWT. I always just did background work from any old 'other' Thread and updated the GUIs from there - it always worked and still does. At some point in time, though, apparently the thinking on this has changed. If I was wrong all along, then I was wrong all along - certainly would not be the first time. But I never read differently and I was trying to see when and why that has changed and could not locate any authoritive write up on the subject. Note that I am only talking about AWT.
    jdk 1.2 has SwingUtilities.isEventDispatchThread(), so i'm not sure how far back you're talking about. jdk 1.1 is a long time ago, so i don't think this whole "single threaded ui is a new-fangled thing" idea really holds.
    This again hooks into the fact that Oracle does not seem to care about backwards compatibility or communication though and it is starting to royally annoy me. Okay perhaps the code wasn't exactly right even for Java 6 because it assumed thread-safety, but when changes are handled like this even people who have worked with Swing for yonks are caught off-guard. What are we supposed to do? Compare the code of the runtime with each new release of Java just to stay up to date!?
    as mentioned in my comment above, swing has been "single threaded" for "yonks", so i'm not sure why anyone would be caught off-guard.
    Each time there is an update now it seems something breaks ... or at least does not work just the same. There's always been some of that, but I do think it's worse. On my mind is all the talk about security issues for Applets ... but that's just as much (or in fact mostly) hackers turning their attention to it as it is the fault of Oracle probably ... though I say that not knowing if hackers were working on this for a long or a short time, and not knowing either any of the internal changes that lead to the problems.
    while i won't disagree with the general thought that oracle seems less concerned with breaking backwards compatibility, constraining the jvm to continue to support old thread-unsafe behavior would probably have kept the jvm in the stone ages. i personally like the current performance of the jvm and don't wish for the return of the "performance" of the 1.1 days.
  • 13. Re: App works on java6 but not on java 7
    mKorbel Explorer
    Currently Being Moderated
    So Oracle thinks they understand Java better than Sun did? :o?

    no, I think that not,

    - probably about removing (long time) depreciated and Thread Safe methods,

    - then maybe another reason why every descriptions and code examples about Swing & Runnable#Thread & invokeLater gone away


    This again hooks into the fact that Oracle does not seem to care about backwards compatibility or communication though and it is starting to royally annoy me

    added (useless) Secondary Loop as compensation, (potential flamewar, my view) with similair logics as SwingWoker invoked from Executor (another two best of shadowing APIs implemented in official JDK, with long and buggy stories)

    +... of the jvm and don't wish for the return of the "performance" of the 1.1 days.+

    I think there no performance issue on todays PCs, because in most cases doesn't matter if code is excelently optimalized or winner of big code mess (simple short code without hard, long computations), those code will be repainted on the screen in very similair/the same time
  • 14. Re: App works on java6 but not on java 7
    abillconsl Explorer
    Currently Being Moderated
    jtahlborn wrote:
    abillconsl wrote:
    gimbal2 wrote:
    Swing is and never was thread safe and has always been advertised as such, even if under the hood it just happened to be in some cases/implementations.
    Oh I know! However, what I meant in my previous-previous comment was that, before swing - or early on with swing because swing was sooooooo slow at first (partly because our PCs were so comparitively slow) I did my GUIs mostly in AWT. I always just did background work from any old 'other' Thread and updated the GUIs from there - it always worked and still does. At some point in time, though, apparently the thinking on this has changed. If I was wrong all along, then I was wrong all along - certainly would not be the first time. But I never read differently and I was trying to see when and why that has changed and could not locate any authoritive write up on the subject. Note that I am only talking about AWT.
    jdk 1.2 has SwingUtilities.isEventDispatchThread(), so i'm not sure how far back you're talking about. jdk 1.1 is a long time ago, so i don't think this whole "single threaded ui is a new-fangled thing" idea really holds.
    This again hooks into the fact that Oracle does not seem to care about backwards compatibility or communication though and it is starting to royally annoy me. Okay perhaps the code wasn't exactly right even for Java 6 because it assumed thread-safety, but when changes are handled like this even people who have worked with Swing for yonks are caught off-guard. What are we supposed to do? Compare the code of the runtime with each new release of Java just to stay up to date!?
    as mentioned in my comment above, swing has been "single threaded" for "yonks", so i'm not sure why anyone would be caught off-guard.
    Each time there is an update now it seems something breaks ... or at least does not work just the same. There's always been some of that, but I do think it's worse. On my mind is all the talk about security issues for Applets ... but that's just as much (or in fact mostly) hackers turning their attention to it as it is the fault of Oracle probably ... though I say that not knowing if hackers were working on this for a long or a short time, and not knowing either any of the internal changes that lead to the problems.
    while i won't disagree with the general thought that oracle seems less concerned with breaking backwards compatibility, constraining the jvm to continue to support old thread-unsafe behavior would probably have kept the jvm in the stone ages. i personally like the current performance of the jvm and don't wish for the return of the "performance" of the 1.1 days.
    I have always only been talking about AWT in this thread/topic. And I mean all the way back to Java 1.0.
1 2 Previous Next

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points