问题一描述
创建3个线程A、B、C、线程A打印字母A,线程B打印字母B,线程C打印字母C;但要求三个线程同时运行并交替打印,即按照ABCABC的顺序打印;
设计思路如下:
第一步:创建ReentrantLock对象,用于在三个线程中加锁;
第二步:创建整型变量,用于控制输出内容;
第三步:创建线程对象,用于输出;
第四步:启动线程对象,输出结果;
具体代码如下;
public class ABC_Lock {
//创建锁对象,保证同时只有一个线程可以得到锁;
static ReentrantLock lock = new ReentrantLock();
//创建整型变量,用于控制输出结果;
static int status = 0;
//内部类必须为static类型的,这样才可以直接在main方法中使用;
static class ThreadA extends Thread {
@Override
public void run() {
while (true) {//此处为保证当前创建的线程能够持续活跃,而不是执行一次就over
lock.lock();//线程手动上锁;
//如果你想控制输出的次数,在if语句中判断status即可;
if (status % 3 == 0) {//判断当status%3 ==0的时候输出A;
System.out.print("A");
//此处值++,并通过判断及lock锁来确定到底执行哪个线程的run方法;
status++;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
lock.unlock();//手动释放线程锁;
}
}
}
static class ThreadB extends Thread {
@Override
public void run() {
while (true) {//此处为保证当前创建的线程能够持续活跃,而不是执行一次就over
lock.lock();//线程手动上锁;
if (status % 3 == 1) {//判断当status%3 ==1的时候输出B;
System.out.print("B");
status++;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
lock.unlock();//手动释放线程锁;
}
}
}
static class ThreadC extends Thread {
@Override
public void run() {
while (true) {//此处为保证当前创建的线程能够持续活跃,而不是执行一次就over
lock.lock();//线程手动上锁;
if (status % 3 == 2) {//判断当status%3 ==2的时候输出B;
System.out.println("C");
status++;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
lock.unlock();//手动释放线程锁;
}
}
}
public static void main(String[] args) {
//启动三个线程并执行
new ThreadA().start();
new ThreadB().start();
new ThreadC().start();
}
}
具体执行结果如下:
"C:\Program Files\Java\jdk1.8.0_91\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2018.1.2\lib\idea_rt.jar=65071:C:\Program Files\JetBrains\IntelliJ IDEA 2018.1.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_91\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\rt.jar;C:\demo\springbootDemo2.0\springbootdemo\springbootdemo-thread\target\classes;E:\ForWorkSoftware\Maven\M2\org\springframework\boot\spring-boot-starter\2.1.3.RELEASE\spring-boot-starter-2.1.3.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\boot\spring-boot\2.1.3.RELEASE\spring-boot-2.1.3.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\spring-context\5.1.5.RELEASE\spring-context-5.1.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\boot\spring-boot-autoconfigure\2.1.3.RELEASE\spring-boot-autoconfigure-2.1.3.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\boot\spring-boot-starter-logging\2.1.3.RELEASE\spring-boot-starter-logging-2.1.3.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;E:\ForWorkSoftware\Maven\M2\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;E:\ForWorkSoftware\Maven\M2\org\apache\logging\log4j\log4j-to-slf4j\2.11.2\log4j-to-slf4j-2.11.2.jar;E:\ForWorkSoftware\Maven\M2\org\apache\logging\log4j\log4j-api\2.11.2\log4j-api-2.11.2.jar;E:\ForWorkSoftware\Maven\M2\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;E:\ForWorkSoftware\Maven\M2\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\spring-core\5.1.5.RELEASE\spring-core-5.1.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\spring-jcl\5.1.5.RELEASE\spring-jcl-5.1.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar;C:\demo\springbootDemo2.0\springbootdemo\springbootdemo-entity\target\classes;E:\ForWorkSoftware\Maven\M2\org\apache\tomcat\embed\tomcat-embed-jasper\9.0.16\tomcat-embed-jasper-9.0.16.jar;E:\ForWorkSoftware\Maven\M2\org\apache\tomcat\embed\tomcat-embed-core\9.0.16\tomcat-embed-core-9.0.16.jar;E:\ForWorkSoftware\Maven\M2\org\apache\tomcat\tomcat-annotations-api\9.0.16\tomcat-annotations-api-9.0.16.jar;E:\ForWorkSoftware\Maven\M2\org\apache\tomcat\embed\tomcat-embed-el\9.0.16\tomcat-embed-el-9.0.16.jar;E:\ForWorkSoftware\Maven\M2\org\eclipse\jdt\ecj\3.15.0\ecj-3.15.0.jar;E:\ForWorkSoftware\Maven\M2\redis\clients\jedis\2.9.1\jedis-2.9.1.jar;E:\ForWorkSoftware\Maven\M2\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;E:\ForWorkSoftware\Maven\M2\org\apache\commons\commons-pool2\2.6.1\commons-pool2-2.6.1.jar;E:\ForWorkSoftware\Maven\M2\com\alibaba\druid\1.1.0\druid-1.1.0.jar;C:\Program Files\Java\jdk1.8.0_91\lib\jconsole.jar;C:\Program Files\Java\jdk1.8.0_91\lib\tools.jar;E:\ForWorkSoftware\Maven\M2\mysql\mysql-connector-java\8.0.15\mysql-connector-java-8.0.15.jar;E:\ForWorkSoftware\Maven\M2\org\mybatis\spring\boot\mybatis-spring-boot-starter\1.3.1\mybatis-spring-boot-starter-1.3.1.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\boot\spring-boot-starter-jdbc\2.1.3.RELEASE\spring-boot-starter-jdbc-2.1.3.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\com\zaxxer\HikariCP\3.2.0\HikariCP-3.2.0.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\spring-jdbc\5.1.5.RELEASE\spring-jdbc-5.1.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\spring-tx\5.1.5.RELEASE\spring-tx-5.1.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\mybatis\spring\boot\mybatis-spring-boot-autoconfigure\1.3.1\mybatis-spring-boot-autoconfigure-1.3.1.jar;E:\ForWorkSoftware\Maven\M2\org\mybatis\mybatis\3.4.5\mybatis-3.4.5.jar;E:\ForWorkSoftware\Maven\M2\org\mybatis\mybatis-spring\1.3.1\mybatis-spring-1.3.1.jar;E:\ForWorkSoftware\Maven\M2\com\github\pagehelper\pagehelper-spring-boot-starter\1.2.3\pagehelper-spring-boot-starter-1.2.3.jar;E:\ForWorkSoftware\Maven\M2\com\github\pagehelper\pagehelper-spring-boot-autoconfigure\1.2.3\pagehelper-spring-boot-autoconfigure-1.2.3.jar;E:\ForWorkSoftware\Maven\M2\com\github\pagehelper\pagehelper\5.1.2\pagehelper-5.1.2.jar;E:\ForWorkSoftware\Maven\M2\com\github\jsqlparser\jsqlparser\1.0\jsqlparser-1.0.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\boot\spring-boot-starter-web\2.1.3.RELEASE\spring-boot-starter-web-2.1.3.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\boot\spring-boot-starter-json\2.1.3.RELEASE\spring-boot-starter-json-2.1.3.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\com\fasterxml\jackson\core\jackson-databind\2.9.8\jackson-databind-2.9.8.jar;E:\ForWorkSoftware\Maven\M2\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.8\jackson-datatype-jdk8-2.9.8.jar;E:\ForWorkSoftware\Maven\M2\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.8\jackson-datatype-jsr310-2.9.8.jar;E:\ForWorkSoftware\Maven\M2\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.8\jackson-module-parameter-names-2.9.8.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\boot\spring-boot-starter-tomcat\2.1.3.RELEASE\spring-boot-starter-tomcat-2.1.3.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.16\tomcat-embed-websocket-9.0.16.jar;E:\ForWorkSoftware\Maven\M2\org\hibernate\validator\hibernate-validator\6.0.14.Final\hibernate-validator-6.0.14.Final.jar;E:\ForWorkSoftware\Maven\M2\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;E:\ForWorkSoftware\Maven\M2\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;E:\ForWorkSoftware\Maven\M2\com\fasterxml\classmate\1.4.0\classmate-1.4.0.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\spring-web\5.1.5.RELEASE\spring-web-5.1.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\spring-beans\5.1.5.RELEASE\spring-beans-5.1.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\spring-webmvc\5.1.5.RELEASE\spring-webmvc-5.1.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\spring-aop\5.1.5.RELEASE\spring-aop-5.1.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\spring-expression\5.1.5.RELEASE\spring-expression-5.1.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\cloud\spring-cloud-starter-netflix-eureka-client\2.0.1.RELEASE\spring-cloud-starter-netflix-eureka-client-2.0.1.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\cloud\spring-cloud-starter\2.0.1.RELEASE\spring-cloud-starter-2.0.1.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\cloud\spring-cloud-context\2.0.1.RELEASE\spring-cloud-context-2.0.1.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\security\spring-security-crypto\5.1.4.RELEASE\spring-security-crypto-5.1.4.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\cloud\spring-cloud-commons\2.0.1.RELEASE\spring-cloud-commons-2.0.1.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\security\spring-security-rsa\1.0.5.RELEASE\spring-security-rsa-1.0.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\bouncycastle\bcpkix-jdk15on\1.56\bcpkix-jdk15on-1.56.jar;E:\ForWorkSoftware\Maven\M2\org\bouncycastle\bcprov-jdk15on\1.56\bcprov-jdk15on-1.56.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\cloud\spring-cloud-netflix-core\2.0.1.RELEASE\spring-cloud-netflix-core-2.0.1.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\boot\spring-boot-starter-aop\2.1.3.RELEASE\spring-boot-starter-aop-2.1.3.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\aspectj\aspectjweaver\1.9.2\aspectjweaver-1.9.2.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\cloud\spring-cloud-netflix-eureka-client\2.0.1.RELEASE\spring-cloud-netflix-eureka-client-2.0.1.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\eureka\eureka-client\1.9.3\eureka-client-1.9.3.jar;E:\ForWorkSoftware\Maven\M2\org\codehaus\jettison\jettison\1.3.7\jettison-1.3.7.jar;E:\ForWorkSoftware\Maven\M2\stax\stax-api\1.0.1\stax-api-1.0.1.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\netflix-commons\netflix-eventbus\0.3.0\netflix-eventbus-0.3.0.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\netflix-commons\netflix-infix\0.3.0\netflix-infix-0.3.0.jar;E:\ForWorkSoftware\Maven\M2\commons-jxpath\commons-jxpath\1.3\commons-jxpath-1.3.jar;E:\ForWorkSoftware\Maven\M2\joda-time\joda-time\2.10.1\joda-time-2.10.1.jar;E:\ForWorkSoftware\Maven\M2\org\antlr\antlr-runtime\3.4\antlr-runtime-3.4.jar;E:\ForWorkSoftware\Maven\M2\org\antlr\stringtemplate\3.2.1\stringtemplate-3.2.1.jar;E:\ForWorkSoftware\Maven\M2\antlr\antlr\2.7.7\antlr-2.7.7.jar;E:\ForWorkSoftware\Maven\M2\com\google\code\gson\gson\2.8.5\gson-2.8.5.jar;E:\ForWorkSoftware\Maven\M2\org\apache\commons\commons-math\2.2\commons-math-2.2.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\archaius\archaius-core\0.7.6\archaius-core-0.7.6.jar;E:\ForWorkSoftware\Maven\M2\com\google\guava\guava\16.0\guava-16.0.jar;E:\ForWorkSoftware\Maven\M2\javax\ws\rs\jsr311-api\1.1.1\jsr311-api-1.1.1.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\servo\servo-core\0.12.21\servo-core-0.12.21.jar;E:\ForWorkSoftware\Maven\M2\com\sun\jersey\jersey-core\1.19.1\jersey-core-1.19.1.jar;E:\ForWorkSoftware\Maven\M2\com\sun\jersey\jersey-client\1.19.1\jersey-client-1.19.1.jar;E:\ForWorkSoftware\Maven\M2\com\sun\jersey\contribs\jersey-apache-client4\1.19.1\jersey-apache-client4-1.19.1.jar;E:\ForWorkSoftware\Maven\M2\org\apache\httpcomponents\httpclient\4.5.7\httpclient-4.5.7.jar;E:\ForWorkSoftware\Maven\M2\org\apache\httpcomponents\httpcore\4.4.11\httpcore-4.4.11.jar;E:\ForWorkSoftware\Maven\M2\commons-codec\commons-codec\1.11\commons-codec-1.11.jar;E:\ForWorkSoftware\Maven\M2\com\google\inject\guice\4.1.0\guice-4.1.0.jar;E:\ForWorkSoftware\Maven\M2\javax\inject\javax.inject\1\javax.inject-1.jar;E:\ForWorkSoftware\Maven\M2\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;E:\ForWorkSoftware\Maven\M2\com\github\vlsi\compactmap\compactmap\1.2.1\compactmap-1.2.1.jar;E:\ForWorkSoftware\Maven\M2\com\github\andrewoma\dexx\dexx-collections\0.2\dexx-collections-0.2.jar;E:\ForWorkSoftware\Maven\M2\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;E:\ForWorkSoftware\Maven\M2\com\fasterxml\jackson\core\jackson-core\2.9.8\jackson-core-2.9.8.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\eureka\eureka-core\1.9.3\eureka-core-1.9.3.jar;E:\ForWorkSoftware\Maven\M2\org\codehaus\woodstox\woodstox-core-asl\4.4.1\woodstox-core-asl-4.4.1.jar;E:\ForWorkSoftware\Maven\M2\javax\xml\stream\stax-api\1.0-2\stax-api-1.0-2.jar;E:\ForWorkSoftware\Maven\M2\org\codehaus\woodstox\stax2-api\3.1.4\stax2-api-3.1.4.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\cloud\spring-cloud-starter-netflix-archaius\2.0.1.RELEASE\spring-cloud-starter-netflix-archaius-2.0.1.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\cloud\spring-cloud-netflix-ribbon\2.0.1.RELEASE\spring-cloud-netflix-ribbon-2.0.1.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\cloud\spring-cloud-netflix-archaius\2.0.1.RELEASE\spring-cloud-netflix-archaius-2.0.1.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\commons-configuration\commons-configuration\1.8\commons-configuration-1.8.jar;E:\ForWorkSoftware\Maven\M2\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\cloud\spring-cloud-starter-netflix-ribbon\2.0.1.RELEASE\spring-cloud-starter-netflix-ribbon-2.0.1.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\ribbon\ribbon\2.2.5\ribbon-2.2.5.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\ribbon\ribbon-transport\2.2.5\ribbon-transport-2.2.5.jar;E:\ForWorkSoftware\Maven\M2\io\reactivex\rxnetty-contexts\0.4.9\rxnetty-contexts-0.4.9.jar;E:\ForWorkSoftware\Maven\M2\io\reactivex\rxnetty-servo\0.4.9\rxnetty-servo-0.4.9.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\hystrix\hystrix-core\1.5.12\hystrix-core-1.5.12.jar;E:\ForWorkSoftware\Maven\M2\org\hdrhistogram\HdrHistogram\2.1.9\HdrHistogram-2.1.9.jar;E:\ForWorkSoftware\Maven\M2\io\reactivex\rxnetty\0.4.9\rxnetty-0.4.9.jar;E:\ForWorkSoftware\Maven\M2\io\netty\netty-codec-http\4.1.33.Final\netty-codec-http-4.1.33.Final.jar;E:\ForWorkSoftware\Maven\M2\io\netty\netty-common\4.1.33.Final\netty-common-4.1.33.Final.jar;E:\ForWorkSoftware\Maven\M2\io\netty\netty-buffer\4.1.33.Final\netty-buffer-4.1.33.Final.jar;E:\ForWorkSoftware\Maven\M2\io\netty\netty-transport\4.1.33.Final\netty-transport-4.1.33.Final.jar;E:\ForWorkSoftware\Maven\M2\io\netty\netty-resolver\4.1.33.Final\netty-resolver-4.1.33.Final.jar;E:\ForWorkSoftware\Maven\M2\io\netty\netty-codec\4.1.33.Final\netty-codec-4.1.33.Final.jar;E:\ForWorkSoftware\Maven\M2\io\netty\netty-transport-native-epoll\4.1.33.Final\netty-transport-native-epoll-4.1.33.Final.jar;E:\ForWorkSoftware\Maven\M2\io\netty\netty-transport-native-unix-common\4.1.33.Final\netty-transport-native-unix-common-4.1.33.Final.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\ribbon\ribbon-core\2.2.5\ribbon-core-2.2.5.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\ribbon\ribbon-httpclient\2.2.5\ribbon-httpclient-2.2.5.jar;E:\ForWorkSoftware\Maven\M2\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\netflix-commons\netflix-commons-util\0.3.0\netflix-commons-util-0.3.0.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\ribbon\ribbon-loadbalancer\2.2.5\ribbon-loadbalancer-2.2.5.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\netflix-commons\netflix-statistics\0.1.1\netflix-statistics-0.1.1.jar;E:\ForWorkSoftware\Maven\M2\io\reactivex\rxjava\1.3.8\rxjava-1.3.8.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\ribbon\ribbon-eureka\2.2.5\ribbon-eureka-2.2.5.jar;E:\ForWorkSoftware\Maven\M2\com\thoughtworks\xstream\xstream\1.4.10\xstream-1.4.10.jar;E:\ForWorkSoftware\Maven\M2\xmlpull\xmlpull\1.1.3.1\xmlpull-1.1.3.1.jar;E:\ForWorkSoftware\Maven\M2\xpp3\xpp3_min\1.1.4c\xpp3_min-1.1.4c.jar;E:\ForWorkSoftware\Maven\M2\javax\servlet\jstl\1.2\jstl-1.2.jar;E:\ForWorkSoftware\Maven\M2\org\projectlombok\lombok\1.18.6\lombok-1.18.6.jar" com.example.springbootdemothread.interview.ABC_Lock
ABC
ABC
ABC
ABC
ABC
A
Process finished with exit code -1
问题二描述
创建两个线程线程1:线程2;线程1打印1、2、3、4;线程2打印a、b、c、d;
现在需要两个线程交替打印,输出样例为:1a2b3c4d;
代码如下:
public class ReentryLockInterview {
static ReentrantLock lock = new ReentrantLock();
static int status = 0;
static String[] str = new String[]{"1","A","2","B","3","C","4","D"};
static class Thread1 extends Thread{
@Override
public void run() {
while(true){
try{
lock.lock();
while(status<8&&status%2==0){
Thread.sleep(1000);
System.out.print(str[status]);
status++;
}
}catch (Exception e){
System.out.println("出现异常了");
}finally {
lock.unlock();
}
}
}
}
static class Thread2 extends Thread{
@Override
public void run() {
while(true){
try{
lock.lock();
while(status<8&&status%2==1){
Thread.sleep(1000);
System.out.print(str[status]);
status++;
}
}catch (Exception e){
System.out.println("出现异常了");
}finally {
lock.unlock();
}
}
}
}
public static void main(String[] args) {
new Thread1().start();
new Thread2().start();
}
输出结果如下:
"C:\Program Files\Java\jdk1.8.0_91\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2018.1.2\lib\idea_rt.jar=49458:C:\Program Files\JetBrains\IntelliJ IDEA 2018.1.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_91\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\rt.jar;C:\demo\springbootDemo2.0\springbootdemo\springbootdemo-thread\target\classes;E:\ForWorkSoftware\Maven\M2\org\springframework\boot\spring-boot-starter\2.1.3.RELEASE\spring-boot-starter-2.1.3.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\boot\spring-boot\2.1.3.RELEASE\spring-boot-2.1.3.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\spring-context\5.1.5.RELEASE\spring-context-5.1.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\boot\spring-boot-autoconfigure\2.1.3.RELEASE\spring-boot-autoconfigure-2.1.3.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\boot\spring-boot-starter-logging\2.1.3.RELEASE\spring-boot-starter-logging-2.1.3.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;E:\ForWorkSoftware\Maven\M2\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;E:\ForWorkSoftware\Maven\M2\org\apache\logging\log4j\log4j-to-slf4j\2.11.2\log4j-to-slf4j-2.11.2.jar;E:\ForWorkSoftware\Maven\M2\org\apache\logging\log4j\log4j-api\2.11.2\log4j-api-2.11.2.jar;E:\ForWorkSoftware\Maven\M2\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;E:\ForWorkSoftware\Maven\M2\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\spring-core\5.1.5.RELEASE\spring-core-5.1.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\spring-jcl\5.1.5.RELEASE\spring-jcl-5.1.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar;C:\demo\springbootDemo2.0\springbootdemo\springbootdemo-entity\target\classes;E:\ForWorkSoftware\Maven\M2\org\apache\tomcat\embed\tomcat-embed-jasper\9.0.16\tomcat-embed-jasper-9.0.16.jar;E:\ForWorkSoftware\Maven\M2\org\apache\tomcat\embed\tomcat-embed-core\9.0.16\tomcat-embed-core-9.0.16.jar;E:\ForWorkSoftware\Maven\M2\org\apache\tomcat\tomcat-annotations-api\9.0.16\tomcat-annotations-api-9.0.16.jar;E:\ForWorkSoftware\Maven\M2\org\apache\tomcat\embed\tomcat-embed-el\9.0.16\tomcat-embed-el-9.0.16.jar;E:\ForWorkSoftware\Maven\M2\org\eclipse\jdt\ecj\3.15.0\ecj-3.15.0.jar;E:\ForWorkSoftware\Maven\M2\redis\clients\jedis\2.9.1\jedis-2.9.1.jar;E:\ForWorkSoftware\Maven\M2\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;E:\ForWorkSoftware\Maven\M2\org\apache\commons\commons-pool2\2.6.1\commons-pool2-2.6.1.jar;E:\ForWorkSoftware\Maven\M2\com\alibaba\druid\1.1.0\druid-1.1.0.jar;C:\Program Files\Java\jdk1.8.0_91\lib\jconsole.jar;C:\Program Files\Java\jdk1.8.0_91\lib\tools.jar;E:\ForWorkSoftware\Maven\M2\mysql\mysql-connector-java\8.0.15\mysql-connector-java-8.0.15.jar;E:\ForWorkSoftware\Maven\M2\org\mybatis\spring\boot\mybatis-spring-boot-starter\1.3.1\mybatis-spring-boot-starter-1.3.1.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\boot\spring-boot-starter-jdbc\2.1.3.RELEASE\spring-boot-starter-jdbc-2.1.3.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\com\zaxxer\HikariCP\3.2.0\HikariCP-3.2.0.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\spring-jdbc\5.1.5.RELEASE\spring-jdbc-5.1.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\spring-tx\5.1.5.RELEASE\spring-tx-5.1.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\mybatis\spring\boot\mybatis-spring-boot-autoconfigure\1.3.1\mybatis-spring-boot-autoconfigure-1.3.1.jar;E:\ForWorkSoftware\Maven\M2\org\mybatis\mybatis\3.4.5\mybatis-3.4.5.jar;E:\ForWorkSoftware\Maven\M2\org\mybatis\mybatis-spring\1.3.1\mybatis-spring-1.3.1.jar;E:\ForWorkSoftware\Maven\M2\com\github\pagehelper\pagehelper-spring-boot-starter\1.2.3\pagehelper-spring-boot-starter-1.2.3.jar;E:\ForWorkSoftware\Maven\M2\com\github\pagehelper\pagehelper-spring-boot-autoconfigure\1.2.3\pagehelper-spring-boot-autoconfigure-1.2.3.jar;E:\ForWorkSoftware\Maven\M2\com\github\pagehelper\pagehelper\5.1.2\pagehelper-5.1.2.jar;E:\ForWorkSoftware\Maven\M2\com\github\jsqlparser\jsqlparser\1.0\jsqlparser-1.0.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\boot\spring-boot-starter-web\2.1.3.RELEASE\spring-boot-starter-web-2.1.3.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\boot\spring-boot-starter-json\2.1.3.RELEASE\spring-boot-starter-json-2.1.3.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\com\fasterxml\jackson\core\jackson-databind\2.9.8\jackson-databind-2.9.8.jar;E:\ForWorkSoftware\Maven\M2\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.8\jackson-datatype-jdk8-2.9.8.jar;E:\ForWorkSoftware\Maven\M2\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.8\jackson-datatype-jsr310-2.9.8.jar;E:\ForWorkSoftware\Maven\M2\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.8\jackson-module-parameter-names-2.9.8.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\boot\spring-boot-starter-tomcat\2.1.3.RELEASE\spring-boot-starter-tomcat-2.1.3.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.16\tomcat-embed-websocket-9.0.16.jar;E:\ForWorkSoftware\Maven\M2\org\hibernate\validator\hibernate-validator\6.0.14.Final\hibernate-validator-6.0.14.Final.jar;E:\ForWorkSoftware\Maven\M2\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;E:\ForWorkSoftware\Maven\M2\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;E:\ForWorkSoftware\Maven\M2\com\fasterxml\classmate\1.4.0\classmate-1.4.0.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\spring-web\5.1.5.RELEASE\spring-web-5.1.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\spring-beans\5.1.5.RELEASE\spring-beans-5.1.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\spring-webmvc\5.1.5.RELEASE\spring-webmvc-5.1.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\spring-aop\5.1.5.RELEASE\spring-aop-5.1.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\spring-expression\5.1.5.RELEASE\spring-expression-5.1.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\cloud\spring-cloud-starter-netflix-eureka-client\2.0.1.RELEASE\spring-cloud-starter-netflix-eureka-client-2.0.1.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\cloud\spring-cloud-starter\2.0.1.RELEASE\spring-cloud-starter-2.0.1.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\cloud\spring-cloud-context\2.0.1.RELEASE\spring-cloud-context-2.0.1.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\security\spring-security-crypto\5.1.4.RELEASE\spring-security-crypto-5.1.4.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\cloud\spring-cloud-commons\2.0.1.RELEASE\spring-cloud-commons-2.0.1.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\security\spring-security-rsa\1.0.5.RELEASE\spring-security-rsa-1.0.5.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\bouncycastle\bcpkix-jdk15on\1.56\bcpkix-jdk15on-1.56.jar;E:\ForWorkSoftware\Maven\M2\org\bouncycastle\bcprov-jdk15on\1.56\bcprov-jdk15on-1.56.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\cloud\spring-cloud-netflix-core\2.0.1.RELEASE\spring-cloud-netflix-core-2.0.1.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\boot\spring-boot-starter-aop\2.1.3.RELEASE\spring-boot-starter-aop-2.1.3.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\aspectj\aspectjweaver\1.9.2\aspectjweaver-1.9.2.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\cloud\spring-cloud-netflix-eureka-client\2.0.1.RELEASE\spring-cloud-netflix-eureka-client-2.0.1.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\eureka\eureka-client\1.9.3\eureka-client-1.9.3.jar;E:\ForWorkSoftware\Maven\M2\org\codehaus\jettison\jettison\1.3.7\jettison-1.3.7.jar;E:\ForWorkSoftware\Maven\M2\stax\stax-api\1.0.1\stax-api-1.0.1.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\netflix-commons\netflix-eventbus\0.3.0\netflix-eventbus-0.3.0.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\netflix-commons\netflix-infix\0.3.0\netflix-infix-0.3.0.jar;E:\ForWorkSoftware\Maven\M2\commons-jxpath\commons-jxpath\1.3\commons-jxpath-1.3.jar;E:\ForWorkSoftware\Maven\M2\joda-time\joda-time\2.10.1\joda-time-2.10.1.jar;E:\ForWorkSoftware\Maven\M2\org\antlr\antlr-runtime\3.4\antlr-runtime-3.4.jar;E:\ForWorkSoftware\Maven\M2\org\antlr\stringtemplate\3.2.1\stringtemplate-3.2.1.jar;E:\ForWorkSoftware\Maven\M2\antlr\antlr\2.7.7\antlr-2.7.7.jar;E:\ForWorkSoftware\Maven\M2\com\google\code\gson\gson\2.8.5\gson-2.8.5.jar;E:\ForWorkSoftware\Maven\M2\org\apache\commons\commons-math\2.2\commons-math-2.2.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\archaius\archaius-core\0.7.6\archaius-core-0.7.6.jar;E:\ForWorkSoftware\Maven\M2\com\google\guava\guava\16.0\guava-16.0.jar;E:\ForWorkSoftware\Maven\M2\javax\ws\rs\jsr311-api\1.1.1\jsr311-api-1.1.1.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\servo\servo-core\0.12.21\servo-core-0.12.21.jar;E:\ForWorkSoftware\Maven\M2\com\sun\jersey\jersey-core\1.19.1\jersey-core-1.19.1.jar;E:\ForWorkSoftware\Maven\M2\com\sun\jersey\jersey-client\1.19.1\jersey-client-1.19.1.jar;E:\ForWorkSoftware\Maven\M2\com\sun\jersey\contribs\jersey-apache-client4\1.19.1\jersey-apache-client4-1.19.1.jar;E:\ForWorkSoftware\Maven\M2\org\apache\httpcomponents\httpclient\4.5.7\httpclient-4.5.7.jar;E:\ForWorkSoftware\Maven\M2\org\apache\httpcomponents\httpcore\4.4.11\httpcore-4.4.11.jar;E:\ForWorkSoftware\Maven\M2\commons-codec\commons-codec\1.11\commons-codec-1.11.jar;E:\ForWorkSoftware\Maven\M2\com\google\inject\guice\4.1.0\guice-4.1.0.jar;E:\ForWorkSoftware\Maven\M2\javax\inject\javax.inject\1\javax.inject-1.jar;E:\ForWorkSoftware\Maven\M2\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;E:\ForWorkSoftware\Maven\M2\com\github\vlsi\compactmap\compactmap\1.2.1\compactmap-1.2.1.jar;E:\ForWorkSoftware\Maven\M2\com\github\andrewoma\dexx\dexx-collections\0.2\dexx-collections-0.2.jar;E:\ForWorkSoftware\Maven\M2\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;E:\ForWorkSoftware\Maven\M2\com\fasterxml\jackson\core\jackson-core\2.9.8\jackson-core-2.9.8.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\eureka\eureka-core\1.9.3\eureka-core-1.9.3.jar;E:\ForWorkSoftware\Maven\M2\org\codehaus\woodstox\woodstox-core-asl\4.4.1\woodstox-core-asl-4.4.1.jar;E:\ForWorkSoftware\Maven\M2\javax\xml\stream\stax-api\1.0-2\stax-api-1.0-2.jar;E:\ForWorkSoftware\Maven\M2\org\codehaus\woodstox\stax2-api\3.1.4\stax2-api-3.1.4.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\cloud\spring-cloud-starter-netflix-archaius\2.0.1.RELEASE\spring-cloud-starter-netflix-archaius-2.0.1.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\cloud\spring-cloud-netflix-ribbon\2.0.1.RELEASE\spring-cloud-netflix-ribbon-2.0.1.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\cloud\spring-cloud-netflix-archaius\2.0.1.RELEASE\spring-cloud-netflix-archaius-2.0.1.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\commons-configuration\commons-configuration\1.8\commons-configuration-1.8.jar;E:\ForWorkSoftware\Maven\M2\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;E:\ForWorkSoftware\Maven\M2\org\springframework\cloud\spring-cloud-starter-netflix-ribbon\2.0.1.RELEASE\spring-cloud-starter-netflix-ribbon-2.0.1.RELEASE.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\ribbon\ribbon\2.2.5\ribbon-2.2.5.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\ribbon\ribbon-transport\2.2.5\ribbon-transport-2.2.5.jar;E:\ForWorkSoftware\Maven\M2\io\reactivex\rxnetty-contexts\0.4.9\rxnetty-contexts-0.4.9.jar;E:\ForWorkSoftware\Maven\M2\io\reactivex\rxnetty-servo\0.4.9\rxnetty-servo-0.4.9.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\hystrix\hystrix-core\1.5.12\hystrix-core-1.5.12.jar;E:\ForWorkSoftware\Maven\M2\org\hdrhistogram\HdrHistogram\2.1.9\HdrHistogram-2.1.9.jar;E:\ForWorkSoftware\Maven\M2\io\reactivex\rxnetty\0.4.9\rxnetty-0.4.9.jar;E:\ForWorkSoftware\Maven\M2\io\netty\netty-codec-http\4.1.33.Final\netty-codec-http-4.1.33.Final.jar;E:\ForWorkSoftware\Maven\M2\io\netty\netty-common\4.1.33.Final\netty-common-4.1.33.Final.jar;E:\ForWorkSoftware\Maven\M2\io\netty\netty-buffer\4.1.33.Final\netty-buffer-4.1.33.Final.jar;E:\ForWorkSoftware\Maven\M2\io\netty\netty-transport\4.1.33.Final\netty-transport-4.1.33.Final.jar;E:\ForWorkSoftware\Maven\M2\io\netty\netty-resolver\4.1.33.Final\netty-resolver-4.1.33.Final.jar;E:\ForWorkSoftware\Maven\M2\io\netty\netty-codec\4.1.33.Final\netty-codec-4.1.33.Final.jar;E:\ForWorkSoftware\Maven\M2\io\netty\netty-transport-native-epoll\4.1.33.Final\netty-transport-native-epoll-4.1.33.Final.jar;E:\ForWorkSoftware\Maven\M2\io\netty\netty-transport-native-unix-common\4.1.33.Final\netty-transport-native-unix-common-4.1.33.Final.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\ribbon\ribbon-core\2.2.5\ribbon-core-2.2.5.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\ribbon\ribbon-httpclient\2.2.5\ribbon-httpclient-2.2.5.jar;E:\ForWorkSoftware\Maven\M2\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\netflix-commons\netflix-commons-util\0.3.0\netflix-commons-util-0.3.0.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\ribbon\ribbon-loadbalancer\2.2.5\ribbon-loadbalancer-2.2.5.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\netflix-commons\netflix-statistics\0.1.1\netflix-statistics-0.1.1.jar;E:\ForWorkSoftware\Maven\M2\io\reactivex\rxjava\1.3.8\rxjava-1.3.8.jar;E:\ForWorkSoftware\Maven\M2\com\netflix\ribbon\ribbon-eureka\2.2.5\ribbon-eureka-2.2.5.jar;E:\ForWorkSoftware\Maven\M2\com\thoughtworks\xstream\xstream\1.4.10\xstream-1.4.10.jar;E:\ForWorkSoftware\Maven\M2\xmlpull\xmlpull\1.1.3.1\xmlpull-1.1.3.1.jar;E:\ForWorkSoftware\Maven\M2\xpp3\xpp3_min\1.1.4c\xpp3_min-1.1.4c.jar;E:\ForWorkSoftware\Maven\M2\javax\servlet\jstl\1.2\jstl-1.2.jar;E:\ForWorkSoftware\Maven\M2\org\projectlombok\lombok\1.18.6\lombok-1.18.6.jar" com.example.springbootdemothread.interview.ReentryLockInterview
1A2B3C4D
Process finished with exit code -1