Pausing/ Resuming Thread Using Tool From java.util.concurrent.

Discussion in 'Java' started by yccheok, Mar 27, 2008.

  1. yccheok

    yccheok Guest

    Hi, may I know is there any technique avaible, for pausing/ resuming
    execution of the thread, which is inside while loop, by using tools
    from java.util.concurrent.

    1) I do not want to use busy pooling, it is ugly and wasting CPU
    resource.

    2) Is the following a proven bug free method?

    public synchronized void pauseWork() {
    request = PAUSE;
    notify();
    }

    public synchronized void resumeWork() {
    if (request == PAUSE) {
    request = RESUME;
    notify();
    }
    }

    private void waitIfPauseRequest()
    throws InterruptedException {

    synchronized (this) {
    if (request == PAUSE) {
    while (request != RESUME) {
    wait();
    }

    request = NORMAL;
    }
    }
    }
    yccheok, Mar 27, 2008
    #1
    1. Advertising

  2. yccheok

    Piotr Kobzda Guest

    yccheok wrote:
    > Hi, may I know is there any technique avaible, for pausing/ resuming
    > execution of the thread, which is inside while loop, by using tools
    > from java.util.concurrent.


    See: java.util.concurrent.locks.LockSupport


    piotr
    Piotr Kobzda, Mar 28, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Timo Nentwig

    java.util.concurrent: Blocking

    Timo Nentwig, Jun 24, 2004, in forum: Java
    Replies:
    4
    Views:
    580
    Timo Nentwig
    Jun 25, 2004
  2. chotchkie
    Replies:
    2
    Views:
    846
    chotchkie
    Aug 4, 2005
  3. Pep
    Replies:
    6
    Views:
    819
  4. Let me Think

    java.util.concurrent

    Let me Think, Oct 29, 2005, in forum: Java
    Replies:
    4
    Views:
    2,881
  5. Replies:
    8
    Views:
    1,181
Loading...

Share This Page