This code creates and starts a thread:
new Thread() {
@Override
public void run() {
try { player.play(); }
catch ( Exception e ) { Sy
You can create an ExecutorService
that only allows a single thread with the Executors.newSingleThreadExecutor method. Once you get the single thread executor, you can call execute
with a Runnable
parameter:
Executor executor = Executors.newSingleThreadExecutor();
executor.execute(new Runnable() { public void run() { /* do something */ } });