amogh112
amogh112

Reputation: 1

java multithreading

I am using netbeans 6.8 .If a sound file is playing, a button on the jframe wont work while the sound file is playing. The user should still be able to press the button while it is playing. I tried to find it but the codes are very complex. Use Main implements runnable{} Multithread this problem.

Upvotes: 0

Views: 152

Answers (3)

AlexR
AlexR

Reputation: 115388

You can either implement thread yourself or use higher level tools like

  1. Executors.newSingleThreadExecutor().execute(command)
  2. java.util.Timer: new Timer().schedule(task, 0)
  3. SwingWorker (asm mentioned by @user802421

Here is how you can run task asynchronously using your own thread:

new Thread() {
    public void run() {
        // write here your code
    }
}.start();

Upvotes: 1

Jim
Jim

Reputation: 22656

It sounds like you are playing a sound on the Event despatch thread. Any long running tasks should not be run on this since, as you've seen, it'll lock the gui.

Upvotes: 5

user802421
user802421

Reputation: 7505

Try SwingWorker. There are Tutorial and StackOverflow question.

Upvotes: 2

Related Questions