请教一个关于多线程中 synchronized 的问题
目的:用两个线程来共同打印a - z,而且没有线程安全问题运行下面代码后,每次只有一个线程启动,这个问题在哪里?
package java16;
public class PrintL implements Runnable{
private char c = 'a';
@Override
public synchronized void run() {
// TODO Auto-generated method stub
while (c <= 'z') {
System.out.println(Thread.currentThread().getName() + ": " + c);
try {
Thread.currentThread().sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
c++;
}
}
public static void main(String[] args) {
PrintL printL = new PrintL();
Thread thread1 = new Thread(printL);
Thread thread2 = new Thread(printL);
thread1.start();
thread2.start();
}
}