Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

Read from port every 10 seconds

Thread view: 
sight - 10 Jun 2006 17:31 GMT
How to make application read from port every 10 s.

Is it smart to create Thread and do it with sleep or with do-while command?
Alex Whitney - 10 Jun 2006 18:01 GMT
You could do it with sleep or a do-while (checking the time at each
loop).  I don't really suggest it, though.  I would just make a thread
that constantly reads data from the port and stores it into a
synchronized queue.  Then you can read data from the queue in whatever
time intervals you want.

> How to make application read from port every 10 s.
>
> Is it smart to create Thread and do it with sleep or with do-while command?
Mark Space - 10 Jun 2006 21:35 GMT
> You could do it with sleep or a do-while (checking the time at each
> loop).  I don't really suggest it, though.  I would just make a thread
> that constantly reads data from the port and stores it into a
> synchronized queue.  Then you can read data from the queue in whatever
> time intervals you want.

I think it kinda depends, but if there is a way to block until new data
is available, sure.

OTOH, some devices don't have a new data flag and just make data
available continuously. For example, a web cam.  Using something like a
10 sec interval to slow the web cam data rate down to something
reasonable is a pretty good idea.

Since the OP is talking about using multiple threads, I assume he has
some sort of shared data/queue/synchronization scheme in mind.

To the OP: well, really I don't know, but I'm pretty sure do {} while
with a sleep() will work.  I'm pretty sure that sleep doesn't guarantee
exact time intervals too.  You'll get "roughly" 10 second intervals.
And sleep() can be interrupted early, which will throw an exception.

But as long as all this is ok, then it should work fine.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.