Take the 2-minute tour ×
    public lyridisplay (java.awt.Frame parent, boolean modal) {
    super(parent, modal); 

    initComponents();//to create a JList

   /* folowing code inside  try preforms DB operations*/
   /*It will return array of  string s*/
       try {
            s = insert.select();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(lyridisplay.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {

    //now set the string s to JList

      jList1.setModel(new javax.swing.AbstractListModel() {
        String[] strings =s;
        public int getSize() { return strings.length; }
        public Object getElementAt(int i) { return strings[i]; }


I think the above code should block the EDT , because of the DB operations before setting up JList and it runs on EDT.But It dosn't.The program runs smooth.I did similar thing before,resulting to blocked EDT and a frozen program.I preformed that code in a separate thread,as adviced by SO users.Why this code dosn't block EDT?

share|improve this question
Indeed, it should block the EDT, but maybe that the select statement is too quick to feel any blocked status for the UI... –  ioan Jan 16 '13 at 12:52
@ioan is the time taken by a select stmt. and insert stmt. same?Cause here i have 5-6 rows in result set,where as last time only one insert blocked my EDT –  joey rohan Jan 16 '13 at 12:58
Why should it block? If insert.select() is quick enough then it won't block. –  Nikita Beloglazov Jan 16 '13 at 13:07
@NikitaBeloglazov last time one insert is blocking the EDT.But select gives many rows to result set...so..? –  joey rohan Jan 16 '13 at 13:14
@joeyrohan sorry, didn't understand. Can you elaborate? –  Nikita Beloglazov Jan 16 '13 at 13:15

1 Answer 1

up vote 2 down vote accepted

Assuming the Swing GUI objects are constructed on the event dispatch thread (EDT), the query very definitely blocks the EDT for some indefinite period of time. As noted in Memory Consistency Properties:


The problem is not how short the time is under ideal conditions, it's how long the time may become when things go awry. GUI users are very sensitive to EDT liveness; a worker thread is good insurance against user dissatisfaction.

share|improve this answer

Your Answer


