Results 1 to 5 of 5
  1. #1
    Paul279 is offline Member
    Join Date
    Oct 2012
    Posts
    45
    Rep Power
    0

    Default SwingWorker - I think problems with eventdispatchThread

    Hello community,

    I have a fully working program. Now i wanted to implement SwingWorkers so that the program does not hang anymore.

    But now I have random errors. Long ago I read something about that this would be a "EventDispatchThread-Problem". So I am not sure but I believe I know what the problem is. But before i can suppose what the problem is here my two Classes.

    First Class: Functions.class
    Second Cl.: WorkingThread.class

    When my program comes to the point that the "Function" class starts a workingThread
    Java Code:
    new Statistikseitenverwaltung("Parameter").execute();[B][/B]
    my worker works fine.

    BUT:
    In my working class there I have references to functions of my Function.class
    MyWorkingClass:
    Java Code:
        protected Void doInBackground() throws Exception {
    doSomethingHere;
    doAFunctionFromTheClassFunctions;
    doAnotherFunctionInTheClassFunctions;
    }
    And in this functions from the Functions.class there are random error. Sometimes here sometimes there.

    So my question:
    When i start (.execute()) a swingworker, and this swing worker references to functions of another class, will these referenced Functions also executed in this "workingThread" or on the "MainEventDispatcherThread" ?

    So when this is not the problem, can anybody explain me where I am wrong?

    I can also reproduce this errors. These happen when I start this workingThread several times short behind each other.
    So maybe there is also a Problem that one working thread executes a function and the next working thread will also execute this function?

    Can anybody explain me this problem?
    Thank you very much

    PS: Hopefully my english is understandable

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: SwingWorker - I think problems with eventdispatchThread

    Quote Originally Posted by Paul279 View Post
    I have a fully working program. Now i wanted to implement SwingWorkers so that the program does not hang anymore.
    So the program is not actually working, right? In any event can you please submit
    a Short, Self Contained, Correct Example that demonstrates the problem
    you are having with SwingWorker. It is hard to follow what is actually going on (and it
    has nothing to do with your English which is fine).

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: SwingWorker - I think problems with eventdispatchThread

    Can you post the errors?
    Full exceptions, including stack traces.
    You might be hitting some threading issues if you're worker threads are accessing the same objects.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    Paul279 is offline Member
    Join Date
    Oct 2012
    Posts
    45
    Rep Power
    0

    Default Re: SwingWorker - I think problems with eventdispatchThread

    Quote Originally Posted by jim829 View Post
    So the program is not actually working, right?
    With that I wanted to say, that the program worked without SwingWorker and with SwingWorker there are several errors.

    In any event can you please submit
    a Short, Self Contained, Correct Example that demonstrates the problem
    you are having with SwingWorker. It is hard to follow what is actually going on (and it
    has nothing to do with your English which is fine).
    I have given short examples of my execution of the SwingWorker and the Swingworker itself. How it is working.
    I can`t post an example how it is working, because that would blow up the border.

    Very often I get also ArrayIndexOutOfBoundsException:
    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 6 >= 6
    This is a huge sign that there is a problem with the Thread and the java.awt.EventDispatchThread.

    Followed you will see my code shortened:
    Java Code:
    public class Statistikseitenverwaltung extends SwingWorker<Void, String>{
    
        String parameter;
        boolean statistikseite;
        SQLFunctions sqlFunctions;
        Controller controller;
        ControllerHauptform controllerH;
    
        public Statistikseitenverwaltung(String parameterr,boolean statistikseitee,
                                    Controller controllerr) {
            this.parameter = parameterr;
            this.statistikseite = statistikseitee;
            this.controller = controllerr;
            this.controllerH = controller.getControllerHauptform();
            this.sqlFunctions = controller.getSqlFunctions();
        }
          
        @Override
        protected Void doInBackground() throws Exception {
            try {                    
            String runde=1;
            String Disziplin="Classic";
            int needThisInformation= 
                    (int) sqlFunctions.getResultFromCustomQuery(
                    "select WELCHER_JRADIOBUTTON_CHECKED".concat(runde)
                    .concat(" from disziplinfaktoren where disziplin_name='")
                    .concat(Disziplin).concat("'"));
    
           } catch (SQLException | ClassNotFoundException ex) {
                controller.trowTheError(ex);
           } 
           return null; //it is okay so
        }
    
        @Override
         protected void done(){
            controller.notifyObserver();
         }
    }
    In the Functions.class
    Java Code:
        public Object getResultFromCustomQuery(String query) throws SQLException
        {
            Object rueckgabe = null;
            rs = statement
                   .executeQuery(query);       
            while (rs.next())
            {
                    rueckgabe = rs.getObject(1);  //Here happens the SQL Exception "HERE IS EXCEPTION"
            }            
            return rueckgabe;     
        }
    When i now run the program and execute this SwingWorker several times short after the first one, I get this ArrayIndexOutOfBoundsException every time with another number => 1 >= 1, 6 >= 6 ...
    and I get very often an SQLException (on the point "HERE IS EXCEPTION")
    Java Code:
    java.sql.SQLException: invalid cursor state: identifier cursor not positioned on row in UPDATE, DELETE, SET, or GET statement: ; ResultSet is positioned after last row
    So I hope this is enough information to recognize my problem

    Thank you very much
    Best regards
    Paul

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: SwingWorker - I think problems with eventdispatchThread

    Exactly I said.
    You have threading issues.
    I'm going to guess that your various instances of this SwingWorker class use the same instance of SQLFunctions.
    So, they "share" the 'rs' ResultSet object and the 'statement'.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. SwingWorker progress?
    By Miromancer in forum AWT / Swing
    Replies: 1
    Last Post: 11-20-2011, 04:36 PM
  2. When do I use SwingWorker?
    By TacoManStan in forum AWT / Swing
    Replies: 8
    Last Post: 10-24-2011, 12:40 AM
  3. SwingWorker
    By 3.14.TR in forum Threads and Synchronization
    Replies: 3
    Last Post: 03-14-2011, 04:53 PM
  4. Using SwingWorker
    By viking90 in forum New To Java
    Replies: 1
    Last Post: 04-24-2010, 09:17 AM
  5. swingworker
    By musiigedeo in forum AWT / Swing
    Replies: 1
    Last Post: 07-26-2007, 12:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •