1 /******************************************************************************* 2 * Copyright (c) 2017 Andrey Loskutov 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * Andrey Loskutov <loskutov@gmx.de> - initial API and implementation 13 *******************************************************************************/ 14 import java.util.concurrent.LinkedTransferQueue; 15 import java.util.concurrent.TransferQueue; 16 17 public class ThreadNameChange { 18 main(String[] args)19 public static void main(String[] args) throws Exception { 20 final TransferQueue queue = new LinkedTransferQueue(); 21 22 Thread t = new Thread(new Runnable() { 23 public void run() { 24 Thread thread = Thread.currentThread(); 25 try { 26 queue.transfer(""); 27 28 thread.setName("2"); 29 30 // give debugger time to check the name 31 queue.transfer(""); 32 } catch (InterruptedException e) { 33 } 34 } 35 }, "1"); 36 t.start(); 37 38 // wait for thread to start, debugger should see "1" at this breakpoint 39 queue.take(); // <-- bp 1 40 System.out.println("thread name: " + t.getName()); 41 42 // second breakpoint, debugger should see "2" as thread name 43 queue.take(); // <-- bp 2 44 System.out.println("thread name: " + t.getName()); 45 } 46 } 47