File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes timer/sound/thread interaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "timer/sound/thread interaction " Watch "timer/sound/thread interaction " New topic
Author

timer/sound/thread interaction

edward tsiller
Greenhorn

Joined: May 03, 2013
Posts: 4
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

Joined: Jun 06, 2007
Posts: 2712
    
    5

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.


SCJP, SCWCD.
|Asking Good Questions|
edward tsiller
Greenhorn

Joined: May 03, 2013
Posts: 4
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

Joined: Jun 06, 2007
Posts: 2712
    
    5

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

Joined: May 03, 2013
Posts: 4
I have change it to thread.sleep(10) ; and still getting delays with showing numbers on the screen
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2712
    
    5

So you mean to say that the sound is played at the desired rate but the display is lagging?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

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

Joined: May 03, 2013
Posts: 4
Yes sir
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: timer/sound/thread interaction
 
Similar Threads
Convert Applet to Stand-alone app
Display Calendar.MINUTE & SECOND with a 0 before the value, if the value is between 0 and 9?
Convert Applet to Stand-alone app
Clock face
What fields does java.util.Date.equals compare?