[6467] in java-interest

home help back first fref pref prev next nref lref last post

Re: A sleeing Thread

daemon@ATHENA.MIT.EDU (Pradeep Badri)
Sun Mar 31 15:05:11 1996

Date:         Sun, 31 Mar 1996 12:00:12 -0800
Reply-To: Java Interest <JAVA-INTEREST@JAVASOFT.COM>
From: Pradeep Badri <pbadri@CISCO.COM>
To: Multiple recipients of list JAVA-INTEREST
              <JAVA-INTEREST@JAVASOFT.COM>
In-Reply-To:  <315E336E.7D96@idsc.gov.eg> from "Ahmed Abdel Hady" at Mar 31,
              96 00:25:34 am

>
> Hello All,
>
> I have a little question, please..
>
> One have to catch an Interrupted Exception when calling
> Thread.sleep();
>
>         try(Thread.sleep(10000);}
>         catch(InterruptedException ex){....}

Hi,

You could use the wait/notify/notifyAll combination to achieve
this.  Create a object and wait on it. i.e.

class A {
        Object waitObj = new Object() ;

        void sleepWell(long tm) {
                try {
                        synchronized(waitObj) {
                                waitObj.wait(tm) ;
                        }
                } catch (InterruptedException e) {
                }
        }

        public void wakeUp() {
                        synchronized(waitObj) {
                                waitObj.notify() ;
                        }
        }
}

So you can use sleepWell and wakeUp combination.

Hope it helps.

Regards,
-pradeep.

Pradeep Badri.
Cisco Systems.


>
> Is there any mean to throw this Exception from outside the
> thread to teminate its sleeping period.
>
>
>
>
> TIA
> Ahmed
>
> -----
> This message has been forwarded via the JAVA-INTEREST
> mailing list.  In order to unsubscribe from this list, send a message to
> listserv@javasoft.com with the command 'signoff JAVA-INTEREST' in
> the message body (not in the subject line).
>
> -----
> This message has been forwarded via the JAVA-INTEREST
> mailing list.  In order to unsubscribe from this list, send a message to
> listserv@javasoft.com with the command 'signoff JAVA-INTEREST' in
> the message body (not in the subject line).
>

-----
This message has been forwarded via the JAVA-INTEREST
mailing list.  In order to unsubscribe from this list, send a message to
listserv@javasoft.com with the command 'signoff JAVA-INTEREST' in
the message body (not in the subject line).

home help back first fref pref prev next nref lref last post