AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Better solution for reading a line from the input for every

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Wed May 16, 2007 7:47 pm    Post subject: Better solution for reading a line from the input for every Reply with quote



I 'm kind of get stuck of finding the best solution for reading a line
from the input file for every 100ms.

My code is the following:

while ( (currentLine = bis.readLine()) != null) {
SimpleThread cc= new SimpleThread("Sleeping for 100ms");
cc.start();
//**** Code to read the file
....
...
//***************************

}


the cc.starts runs sleep(100),so the thread sleeps 100ms. The while
loop executes until end of file

Is it the right way to read a line for every 100ms? Is there better
way to do it?
Back to top
Matt Humphrey
Guest





PostPosted: Wed May 16, 2007 10:26 pm    Post subject: Re: Better solution for reading a line from the input for ev Reply with quote



<saturnlee (AT) yahoo (DOT) com> wrote in message
news:1179326838.882170.5350 (AT) l77g2000hsb (DOT) googlegroups.com...
|I 'm kind of get stuck of finding the best solution for reading a line
| from the input file for every 100ms.
|
| My code is the following:
|
| while ( (currentLine = bis.readLine()) != null) {
| SimpleThread cc= new SimpleThread("Sleeping for 100ms");
| cc.start();
| //**** Code to read the file
| ....
| ...
| //***************************
|
| }
|
|
| the cc.starts runs sleep(100),so the thread sleeps 100ms. The while
| loop executes until end of file
|
| Is it the right way to read a line for every 100ms? Is there better
| way to do it?

No--your code causes a separate thread to wait without slowing down the
reading. If you want the reading of each line to be delayed by 100ms, just
put Thread.sleep(100) in the loop to make it wait each time around. There's
no need for a separate thread.

It seems very unusual to me to slow down reading. Perhaps if you explain
why you want to do it someone can help find a better solution for what you
are really trying to accomplish.

Matt Humphrey matth (AT) ivizNOSPAM (DOT) com http://www.iviz.com/
Back to top
Guest






PostPosted: Thu May 17, 2007 12:45 am    Post subject: Re: Better solution for reading a line from the input for ev Reply with quote



On May 16, 1:26 pm, "Matt Humphrey" <m...@ivizNOSPAM.com> wrote:
Quote:
saturn...@yahoo.com> wrote in message

news:1179326838.882170.5350 (AT) l77g2000hsb (DOT) googlegroups.com...
|I 'm kind of get stuck of finding the best solution for reading a line
| from the input file for every 100ms.
|
| My code is the following:
|
| while ( (currentLine = bis.readLine()) != null) {
| SimpleThread cc= new SimpleThread("Sleeping for 100ms");
| cc.start();
| //**** Code to read the file
| ....
| ...
| //***************************
|
| }
|
|
| the cc.starts runs sleep(100),so the thread sleeps 100ms. The while
| loop executes until end of file
|
| Is it the right way to read a line for every 100ms? Is there better
| way to do it?

No--your code causes a separate thread to wait without slowing down the
reading. If you want the reading of each line to be delayed by 100ms, just
put Thread.sleep(100) in the loop to make it wait each time around. There's
no need for a separate thread.

It seems very unusual to me to slow down reading. Perhaps if you explain
why you want to do it someone can help find a better solution for what you
are really trying to accomplish.

Matt Humphrey m...@ivizNOSPAM.comhttp://www.iviz.com/

I need to read every line per 100ms, in order to simulate the input to
a video network.
Back to top
Patricia Shanahan
Guest





PostPosted: Thu May 17, 2007 12:59 am    Post subject: Re: Better solution for reading a line from the input for ev Reply with quote

saturnlee (AT) yahoo (DOT) com wrote:
Quote:
On May 16, 1:26 pm, "Matt Humphrey" <m...@ivizNOSPAM.com> wrote:
saturn...@yahoo.com> wrote in message

news:1179326838.882170.5350 (AT) l77g2000hsb (DOT) googlegroups.com...
|I 'm kind of get stuck of finding the best solution for reading a line
| from the input file for every 100ms.
|
| My code is the following:
|
| while ( (currentLine = bis.readLine()) != null) {
| SimpleThread cc= new SimpleThread("Sleeping for 100ms");
| cc.start();
| //**** Code to read the file
| ....
| ...
| //***************************
|
| }
|
|
| the cc.starts runs sleep(100),so the thread sleeps 100ms. The while
| loop executes until end of file
|
| Is it the right way to read a line for every 100ms? Is there better
| way to do it?

No--your code causes a separate thread to wait without slowing down the
reading. If you want the reading of each line to be delayed by 100ms, just
put Thread.sleep(100) in the loop to make it wait each time around. There's
no need for a separate thread.

It seems very unusual to me to slow down reading. Perhaps if you explain
why you want to do it someone can help find a better solution for what you
are really trying to accomplish.

Matt Humphrey m...@ivizNOSPAM.comhttp://www.iviz.com/

I need to read every line per 100ms, in order to simulate the input to
a video network.


You may get more accurate timing if you think in terms of popping the
head item from a BlockingQueue every 100 ms, and have a separate thread
that just reads data and puts it on the queue. When the queue is full,
it will wait for space.

The queue would provide a buffer, insulating the once every 100 ms
activities from I/O latency.

Patricia
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.