Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Multithreading question

  1. #1
    Member Hikaros's Avatar
    Join Date
    Sep 2013
    Posts
    42
    My Mood
    Love
    Thanks
    10
    Thanked 2 Times in 2 Posts

    Default Multithreading question

    So i've read a lot and i just don't get it. Sure, i know that only GUI stuff should be in the EDT and that lengthy stuff, like database calls has to be done in another thread but i seriously don't understand where do i have to do it or if i am doing it right because i feel the program runs just the same.

    the basic structure of the class is:

    Class class1 extends JInternalFrame{
     
        class1(){
            ...all the gui stuff....
     
            ...action listeners (the queries to database are here)...
        }
     
    }

    it is a login screen so it has two buttons, accept and cancel.
    however there is a textfield with a keyadapter that executes queries each time a key is pressed.

    anyways i've tried putting every action listener inside another thread like this:

    Class class1 extends JInternalFrame{
     
        class1(){
            ...all the gui stuff....
     
            Thread t = new Thread(){
                public void run(){
                    ...action listeners (the queries to database are here)...
            }}; 
     
            t.start();       
        }
     
    }

    but i still feel the same, the moment when it takes about 300 ms to do something (the accept button is like"clicked" animation stuck) is when the login is successful and then a method from a another class is called and it builds a menu based of a structure in the database. How am i supposed to approach this? ):


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Multithreading question

    You say you've read a bunch, but it seems your understanding of the basic concepts are still a bit off. That's okay, it's not an easy topic. Try reading this Lesson to see if it clears up anything for you. In this discussion you should more clearly understand what is meant by "Swing is not thread safe," and see that the programmer should not create other Threads to run with the Swing app in the EDT.
    i seriously don't understand where do i have to do it or if i am doing it right because i feel the program runs just the same.
    Then try to clarify your questions. We can't know what "runs just the same" means. It sounds like you're experiencing unacceptable/noticeable delays in GUI performance and you're wondering how to fix that, but I'm not sure I understand what you're asking. Also, it's difficult to tell the source of the problem without seeing a runnable example that demonstrates what you've tried and what you're seeing. Granted, if your example involves searching a large database, you can't show that so don't try, but give a better explanation. Based on the little bit you've shown, it does appear that you're doing it wrong, so hopefully the Lesson I pointed you to will help.

    Come back when you're ready to discuss further.

Similar Threads

  1. Complicated Multithreading
    By didingnuriska in forum Threads
    Replies: 16
    Last Post: April 19th, 2013, 02:17 PM
  2. Multithreading
    By Miths in forum Java Theory & Questions
    Replies: 10
    Last Post: December 17th, 2012, 02:46 AM
  3. Multithreading Problem
    By Staticity in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 2nd, 2012, 07:39 PM
  4. Java Multithreading Example - Issues
    By vijayinani in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 30th, 2012, 10:46 AM
  5. Multithreading in java
    By skillet in forum Java Theory & Questions
    Replies: 1
    Last Post: March 17th, 2012, 07:32 AM