If the "start com port listener" line is not a starting a separate thread and its a blocking read then your program will not even get to the sleep until a "port event" occurs (something is read from the socket).

Your program will never read a second "port event" because the "start com port listener" line is only executed once.

Hema and sktom are correct - put the port listener in a separate thread, read the socket in an infinite loop (it blocks if there is nothing to read) and remove the Thread.sleep() (it serves no purpose). If an event takes a non-trivial amount of time to process, then handle them in a separate thread so the "reader" thread can return to reading as quickly as possible.

Tom

-----Original Message-----
From: Steven [
mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 24, 2002 12:36 AM
To: JDJList
Subject: [jdjlist] Re: Thread.sleep problem...Please help


Hi,

I'd like to state more clear about my problem:

(single thread application)
main(){
    start com port listener
        if(event occur)
            println("hello")

    println("before sleep")
    Thread.sleep(10000) //slepp 10 seconds
    println("after sleep")
}

how can the "hello" be printed if the serial port event occurred during the
10 seconds sleeping time?
Thanks All...hope can help



Steven


----- Original Message -----
From: <[EMAIL PROTECTED]>
To: "JDJList" <[EMAIL PROTECTED]>
Sent: Wednesday, July 24, 2002 9:27 AM
Subject: [jdjlist] Re: Thread.sleep problem...Please help


> You can always spawn off a second thread from your main thread.  One way
to
> do this is to have your application's class implement the Runnable
> interface, then from your main thread issue:
>
> Thread t = new Thread(this);
> t.start();
>
> This will start your second thread running in Runnable's public void run()
> method which you'd need to implement.
>
> -----Original Message-----
> From: Steven [
mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, July 23, 2002 6:10 PM
> To: JDJList
> Subject: [jdjlist] Re: Thread.sleep problem...Please help
>
>
> Hi,
>
> Thanks for ur opinion. But what if my application has only single thread?
> are there any alternatives?
>
> ----- Original Message -----
> From: "Hema Venkataraman" <[EMAIL PROTECTED]>
> To: "JDJList" <[EMAIL PROTECTED]>
> Sent: Friday, April 05, 2002 12:42 PM
> Subject: [jdjlist] Re: Thread.sleep problem...Please help
>
>
> > You have a thread for a COM port which will be listening for events. You
> > have another Thread to do the actions to be done. Make them sleep  for
few
> > seconds. You can also use wait and notify in case actions are to be
taken
> > when a particular event happens.
> >
> >
> >
> >
> > To change your membership options, refer to:
> >
http://www.sys-con.com/java/list.cfm
>
>
> To change your membership options, refer to:
>
http://www.sys-con.com/java/list.cfm
>
> To change your membership options, refer to:
>
http://www.sys-con.com/java/list.cfm


To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm

To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm

THIS TRANSMISSION, INCLUDING ANY ATTACHMENTS OR FILES,

CONTAINS AIRNET COMMUNICATIONS CORPORATION CONFIDENTIAL

AND PROPRIETARY INFORMATION WHICH MAY BE OTHERWISE EXEMPT

FROM DISCLOSURE.

The information is intended to be for the exclusive use of the individual

or entity named above. If you are not the intended recipient,

be advised that any disclosure, copying, distribution or other use

of this information is strictly prohibited. If you have received this

transmission in error, please notify us by telephone at 1-321-984-1990 or

by email to [EMAIL PROTECTED] immediately and do not read, print

or save this information in any manner.

Reply via email to