Results 1 to 6 of 6

Thread: Java Threads

  1. #1
    dalu is offline Member
    Join Date
    Mar 2011
    Posts
    23
    Rep Power
    0

    Default Java Threads

    Hi,

    I have a user input class that reads the user input values (From UI) and another class that computes some complex calculations using these values. I want the computation class to be independent of the user input class. Can this computation class be implemented as a thread to serve my purpose?? Can anyone help me??

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,232
    Rep Power
    19

    Default

    Assuming that's a Swing GUI (which you didn't tell us), check out this tutorial:
    Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    Particularly the section on SwingWorker.

    db

  3. #3
    Solarsonic is offline Senior Member
    Join Date
    Mar 2011
    Posts
    261
    Rep Power
    4

    Default

    Yes, and Darryl is right with the SwingWorker, but you can just create a regular Thread (read up on threads).

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

    Default

    Quote Originally Posted by Solarsonic View Post
    Yes, and Darryl is right with the SwingWorker, but you can just create a regular Thread (read up on threads).
    But if you do this, then you are responsible for making sure that Swing calls are done on the EDT only. Darryl's link will describe what the EDT is and why it's important. The SwingWorker will automate some of this for you.

  5. #5
    dalu is offline Member
    Join Date
    Mar 2011
    Posts
    23
    Rep Power
    0

    Default

    Hi,
    I read the tutorial and implemented it. Now I am facing another problem.
    I have another example where I have three different stages. First stage is a GUI(Swing). When I click a button from the GUI, I perform an action. When I reach a certain point during that action(say action-1), I need to start another action(say action-2). While I need to run only a single instance of action-1 and it is a dependent process, I want to run the multiple instances of action-2 and they are independent processes. I want to create atleast a thousand instances of action-2 at a moment (my main purpose is to give each user a thread of action-2 and I am considering 1000 users. ) Is this possible??

  6. #6
    dalu is offline Member
    Join Date
    Mar 2011
    Posts
    23
    Rep Power
    0

    Default

    Hi,
    Let me add my code snippets here so that it will be more clear to u..

    public class getvalues()
    {
    ...
    ....
    ...
    if(key == name)
    userTest utest = new userTest();
    new Thread(utest).start();
    ...
    ....
    ....
    .....
    }


    and I have a userTest class implementing runnable interface

    class userTest implements Runnable {
    public void run() {
    System.out.println("Entered Thread ");
    ....
    ....
    ...

    }


    Here, my requirement is that class "a" should not depend on thread userTest. Even if the userTest is being blocked due to some reason, class a should continue its execution. Here, with respect to my implementation, class a waits until the execution of userTest is finished executing. Can any one help me plz...

Similar Threads

  1. Java threads
    By naik_amit in forum Threads and Synchronization
    Replies: 1
    Last Post: 08-25-2010, 11:21 PM
  2. Threads in Java
    By ZeCute in forum New To Java
    Replies: 2
    Last Post: 05-20-2010, 04:06 PM
  3. How to use Java threads
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-09-2008, 06:30 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
  •