Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem with Threads and System resource usage , need advice on using Thread or not..  RSS feed

 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thank you for reading my post.
I have a problem with threads and timers ,
my problem is :
I send some data over a port to some device , now i should wait until the device send me an acknoledge
after device send the ack i will go with sendingnext data.
Now , after i send first data , i execute a thread
inside that thread , i have a while loop
inside the loop i read the port until the ACK port values go to true,
then i exit the loop and exit the thread too.

this solution works , but it has some other problems
1-in this case java process will eat all CPU cycles
2-my application will GUI does not response good enought

How i can solve this problem ?

Thanks


here is the code that i create the thread and execute it

 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could put a "Thread.sleep()" call into that while loop, so it wouldn't poll the parallel port quite so often. I bet that even sleeping for 5 milliseconds would make a big difference.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Thread.yield() might also work.

Moving to Threads and Synchronization...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!