Link to home
Start Free TrialLog in
Avatar of agrees
agrees

asked on

Creating new threads from a static context

Hi all,

My application has an abstract utility class which makes sounds.  It does this via static accessor methods like this:

public static void playError() {
  playSound(ERROR);
}

This is fine, but I want some of these methods to play the sound in a new thread, something like this:

public static void playClick() {
  playThreadSound(CLICK);
}

private static void playThreadSound( URL CLICK) {
  // ---- This won't work, trying to create instance from a static context!
  SoundThread thread = new SoundThread(CLICK);    
  thread.start();
}

Can anyone show me how to get the functionality I require, without having to create an instance of my Utility class?  Is what I'm trying to do sensible?
SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of agrees
agrees

ASKER

Bingo, just what I was after, thanks zzynx!

I'll give it a bit just in case anyone wants to argue a better way, then give you the points! :)
OK :)
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>   // ---- This won't work, trying to create instance from a static context!

you can create an instance from a static context (unless it is an inner class).
If it is an inner class then either move it from being an inner class or make it static (the class that is).

Thank you
8-)