Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Threads in Java

  1. #1
    New to the CF scene
    Join Date
    Feb 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Threads in Java

    If I created a subclass called testThread, put a counter in it that increments every 100 milliseconds, and add a public method to retrieve the counter value, would the following be correct?

    class clockThread extends Thread {

    int counter = 0;

    public clockThread(int number) {

    while(true) {

    counter = number;
    try {
    Thread.sleep(100);
    }
    catch ( InterruptedException e) {}
    counter ++

    }
    }
    }

    How would I create an applet that has two instances of testThread and uses the paint method to display the counters in two threads? How would I adjust the priorities of the two threads?

    Your help in understanding this will be appreciated.

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    Spain
    Posts
    420
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Java!=Javascript.
    Try to put this message in the "Computer Programming" Forum
    Don't resist to assimilation. Billions of Borgs can't be wrong!

  • #3
    New to the CF scene
    Join Date
    Feb 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, thanks for the reply; but .... I do not have permissions to move this thread. Can the administrator help by moving this thread to Computer Programming? If any one in this forum has a solution to the initial question, that would be great.

    Thanks.


  •  

    Posting Permissions

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