Results 1 to 7 of 7
  1. #1
    chiragkini is offline Member
    Join Date
    Jan 2009
    Posts
    14
    Rep Power
    0

    Default How to stop thread from being jumping off the code without executing it.....

    Hi friends,
    This is chirag kini, I am working on Live project of Online Lottery System. (Client - Server architecture). My problem is, whenever i try to call a methods from running thread, says:

    function1();
    function2(); (in my run() method)

    sometimes it executes both functions perfectly, and sometimes it simply skips off function2();
    Even sometimes function2() gets called, it doesnot repaint the Application with the changes done in function2().
    Which results in instability in application in client side.

    I am talking about the client side threads.....


    SO please guys, if anyone knows how to tackle this..... pleaaaaaaaaaaaaase
    help me out...

    waiting for all....

    Thanks in Advance.....

  2. #2
    Thennarasu's Avatar
    Thennarasu is offline Member
    Join Date
    Jan 2009
    Location
    Chennai, Tamilnadu
    Posts
    39
    Rep Power
    0

    Default its is what thread means....

    in thread , nothing is guaranteed.......
    try using synchronized methods...
    instead of thread its will be best if u maintain session if its a web application.

  3. #3
    Thennarasu's Avatar
    Thennarasu is offline Member
    Join Date
    Jan 2009
    Location
    Chennai, Tamilnadu
    Posts
    39
    Rep Power
    0

    Default

    javamex.com

    check this

  4. #4
    chiragkini is offline Member
    Join Date
    Jan 2009
    Posts
    14
    Rep Power
    0

    Default

    thanxxxx dude....

    My application is client server architecture where my client is swing application. In my application i need to execute some threads which are requesting the server database for any changes in table values........

  5. #5
    Thennarasu's Avatar
    Thennarasu is offline Member
    Join Date
    Jan 2009
    Location
    Chennai, Tamilnadu
    Posts
    39
    Rep Power
    0

    Default

    do u mean

    Swing threading and the event-dispatch thread...?

  6. #6
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Sounds like your problem is not with your thread but with the fact that your thread is attempting to update Swing components. That can certainly lead to unpredictable results.

    The problem is that Swing runs in its own thread, called the EDT. Your thread may well have made "local copies" of the components you update, so the EDT never sees the updates.

    The EventQueue class is the basic means to accessing the EDT. Try code like this:
    Java Code:
    final String finalValue1 = value1;
    final int finalValue2 = value2;
    EventQueue.invokeLater(new Runnable() {
      public void run() {
        component1.setText(finalValue1);
        component2.setValue(finalValue2);
      }
    });
    EventQueue.invokeLater() allows you to run code on the EDT. The EventQueue class is responsible for making sure everything runs in order.

    The reason for the two "final" variables is that only final local variables are visible from inside an anonymous inner class. That's a bit annoying, but it's no big deal.

  7. #7
    chiragkini is offline Member
    Join Date
    Jan 2009
    Posts
    14
    Rep Power
    0

    Smile

    hey thanks steve.... u caught my problem perfectly....
    I will try your solution and will let you know if its works.....
    Thanks for replies

Similar Threads

  1. Can you stop a gif? xd
    By Exhonour in forum New To Java
    Replies: 0
    Last Post: 01-16-2009, 09:44 PM
  2. how to stop a thread
    By willemjav in forum Advanced Java
    Replies: 19
    Last Post: 09-10-2008, 08:11 AM
  3. The safe way to stop a thread
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-09-2008, 07:31 PM
  4. Eclipse - jumping to method definition
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-07-2007, 03:52 PM
  5. Executing Ant code pragramatically
    By MikeO in forum Advanced Java
    Replies: 0
    Last Post: 07-24-2007, 10:34 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
  •