Results 1 to 9 of 9
  1. #1
    ravjot28 is offline Member
    Join Date
    Jun 2008
    Posts
    87
    Rep Power
    0

    Default MultiThreading Problem

    I am having a basic problem

    I have a class GUi which is showing the GUi of the project
    and a class where i process the data

    Now when i click on start button the class which process the data is called and when the data being processed at that time GUi frame hangs and buttons get inactive.

    Now i know it will be solved by threading so can u help me how to do it .

    Eg:

    GUI.java
    Java Code:
    class GUI
    {
    .....
    void actionListener(...)
    {
        new A();
    }
    }
    A.java
    Java Code:
    class A
    {
    ......
    }
    now when A is called the frame in GUI gets inactive but the data processing is performed normally.

    Thanks in advance

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    You can create threads in two ways, using Thread class as well as Runnable interface.

    Java Code:
    class A extends Thread {
    
       public void run() {
           // Implementation
       }  
    
    }
    Then start the thread.

    Java Code:
    class B { 
       
       .......
       A objA = new A();
       objA.start();
    
    }
    That's very basis of Thread. Read more about in Suns' official website.

    Lesson: Concurrency (The Java™ Tutorials > Essential Classes)

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Your problem is that you're calling a long-running process on the EDT, the Event Dispatch Thread, the main thread that Swing uses to do painting and user interaction, and when this happens, Swing simply freezes in its tracts. The solution is to do your background process in a a background thread like a SwingWorker. For details, please look here: Concurrency in Swing

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    And also search the forum, Java Tip section as well. You can find lots of similar discussion related to.

  5. #5
    ravjot28 is offline Member
    Join Date
    Jun 2008
    Posts
    87
    Rep Power
    0

    Default

    thank you i have solved it by running the data processing in new thread

    thank u

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  7. #7
    ravjot28 is offline Member
    Join Date
    Jun 2008
    Posts
    87
    Rep Power
    0

    Default

    well as per my knowledge the thread is marked solved isnt it?

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Oops, I just seen that. Sorry about lol, normally I'm accessing threads from the list, and hard to see it at once. )

  9. #9
    ravjot28 is offline Member
    Join Date
    Jun 2008
    Posts
    87
    Rep Power
    0

    Default

    no problem , well have to read my new "MultiThreading part 2" thread i need help so desperately please if you can help me

Similar Threads

  1. Log 4j Multithreading
    By joe2010 in forum Threads and Synchronization
    Replies: 1
    Last Post: 01-31-2010, 04:48 AM
  2. problem using ObjectOutputStream in multithreading
    By sanjeevbindroo in forum Networking
    Replies: 3
    Last Post: 10-15-2009, 09:00 AM
  3. Applet and multithreading
    By pricelessjunk in forum Threads and Synchronization
    Replies: 1
    Last Post: 08-03-2009, 10:47 PM
  4. multithreading
    By shilpa.krishna in forum New To Java
    Replies: 2
    Last Post: 06-27-2008, 05:18 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
  •