File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

timer/sound/thread interaction

 
edward tsiller
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good morning !
I m new to Java ,but I believe this question about thread organisation in my program ..Can you please help me to optimize it ?
Program has to do count time and show it on display and at the same time play appropriate sound (frequency of sound is taken from array freq[]
.When i m trying to run program it produced appropriate sounds ,but timer slows down and count time with delays up to 10 seconds ...
What should i do ?
Thank you very much
Edward
Here is code

 
Amit Ghorpade
Bartender
Posts: 2851
10
Fedora Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Javaranch .
Please UseCodeTags for posting your code, that way it is more readable.
I have added them for you in the post above.
 
edward tsiller
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok .Thank you .Will use code tags .Can you please give me suggestion why time on my display slows down after i start to use double array freq[]?
Thank you very much
Edward
 
Amit Ghorpade
Bartender
Posts: 2851
10
Fedora Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think the slowdown has anything to do with the freq[].
Only thing I see that adds delay is the Thread.sleep(1000).
 
edward tsiller
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have change it to thread.sleep(10) ; and still getting delays with showing numbers on the screen
 
Amit Ghorpade
Bartender
Posts: 2851
10
Fedora Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you mean to say that the sound is played at the desired rate but the display is lagging?
 
Paul Clapham
Sheriff
Pie
Posts: 20177
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would rewrite that code using Swing components, and use a Swing timer to do the repetitive screen updates. There's really no reason to use the old AWT components since Swing replaced them nearly 15 years ago, and trying to get multiple threads working with the old AWT components is also a dead subject.

It's possible that just replacing your infinite loop by a Swing timer might solve your problem, but really I wouldn't continue with those antique AWT components.
 
edward tsiller
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes sir
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic