[concurrency-interest] Setting the name of a Thread

Mike Quilleash mike.quilleash at subexazure.com
Wed Aug 2 12:57:12 EDT 2006


Thanks.

That's a lot better and neater than what I had.  I've put the proper ECS
back in and it all works perfectly.

Cheers.

-----Original Message-----
From: Ernst, Matthias [mailto:matthias.ernst at coremedia.com] 
Sent: 02 August 2006 16:25
To: Mike Quilleash ; concurrency-interest at cs.oswego.edu
Subject: AW: [concurrency-interest] Setting the name of a Thread

> I have a ThreadPoolExecutor that runs an arbitrary number of 
> housekeeping tasks in a system.  Each of these tasks implements an 
> interface extends Runnable and has getName().
> I want to submit each of these to the executor and have the name of 
> the thread set to the getName().

Why don't you submit wrappers that implement the name-setting?

execute(final NamedRunnable namedRunnable) {
  tpe.execute(new Runnable() {
    public void run() {
      Thread t = Thread.currentThread();
      String oldName = t.getName();
      t.setName(namedRunnable.getName());
      try {
        namedRunnable.run();
      } finally {
        t.setName(oldName);
      }
    }
  });
}

Matthias


 This e-mail is bound by the terms and conditions described at http://www.subexazure.com/mail-disclaimer.html




More information about the Concurrency-interest mailing list