|
@@ -1,6 +1,7 @@
|
|
package com.zhili.stationcontrol.tts.service.impl;
|
|
package com.zhili.stationcontrol.tts.service.impl;
|
|
|
|
|
|
import com.zhili.stationcontrol.tts.service.MusicService;
|
|
import com.zhili.stationcontrol.tts.service.MusicService;
|
|
|
|
+import lombok.SneakyThrows;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -29,7 +30,7 @@ public class MusicServiceImpl implements MusicService, Runnable {
|
|
Thread thread;
|
|
Thread thread;
|
|
|
|
|
|
@PostConstruct
|
|
@PostConstruct
|
|
- public void init(){
|
|
|
|
|
|
+ public void init() {
|
|
this.thread = new Thread(this);
|
|
this.thread = new Thread(this);
|
|
this.thread.start();
|
|
this.thread.start();
|
|
}
|
|
}
|
|
@@ -55,47 +56,51 @@ public class MusicServiceImpl implements MusicService, Runnable {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ @SneakyThrows
|
|
@Override
|
|
@Override
|
|
public void run() {
|
|
public void run() {
|
|
while (true) {
|
|
while (true) {
|
|
- try {
|
|
|
|
- Thread.sleep(500);
|
|
|
|
- log.info("----------");
|
|
|
|
- log.info("startCmd:{},endCmd:{},repeat:{},cmd:{}", startCmd, endCmd, repeat, cmd);
|
|
|
|
- log.info("p:{},p.isAlive:{}", p, p == null ? null : p.isAlive());
|
|
|
|
- if (startCmd) {
|
|
|
|
- startCmd = false;
|
|
|
|
- if (p != null) {
|
|
|
|
- p.destroyForcibly();
|
|
|
|
- p.waitFor();
|
|
|
|
- p = null;
|
|
|
|
|
|
+ Thread.sleep(500);
|
|
|
|
+ synchronized (this) {
|
|
|
|
+ try {
|
|
|
|
+ log.info("----------");
|
|
|
|
+ log.info("startCmd:{},endCmd:{},repeat:{},cmd:{}", startCmd, endCmd, repeat, cmd);
|
|
|
|
+ log.info("p:{},p.isAlive:{}", p, p == null ? null : p.isAlive());
|
|
|
|
+ if (startCmd) {
|
|
|
|
+ startCmd = false;
|
|
|
|
+ if (p != null) {
|
|
|
|
+ p.destroyForcibly();
|
|
|
|
+ p.waitFor();
|
|
|
|
+ p = null;
|
|
|
|
+ }
|
|
|
|
+ p = Runtime.getRuntime().exec(cmd);
|
|
}
|
|
}
|
|
- p = Runtime.getRuntime().exec(cmd);
|
|
|
|
- }
|
|
|
|
- if (endCmd) {
|
|
|
|
- endCmd = false;
|
|
|
|
- if (p != null) {
|
|
|
|
- p.destroyForcibly();
|
|
|
|
- p.waitFor();
|
|
|
|
- p = null;
|
|
|
|
|
|
+ if (endCmd) {
|
|
|
|
+ endCmd = false;
|
|
|
|
+ if (p != null) {
|
|
|
|
+ p.destroyForcibly();
|
|
|
|
+ p.waitFor();
|
|
|
|
+ p = null;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
- if (!startCmd && !endCmd && repeat && cmd != null) {
|
|
|
|
- if (p != null) {
|
|
|
|
- boolean exit = p.waitFor(500, TimeUnit.MILLISECONDS);
|
|
|
|
- if (exit) {
|
|
|
|
- log.info("repeat");
|
|
|
|
- p = Runtime.getRuntime().exec(cmd);
|
|
|
|
|
|
+ if (!startCmd && !endCmd && repeat && cmd != null) {
|
|
|
|
+ if (p != null) {
|
|
|
|
+ boolean exit = p.waitFor(500, TimeUnit.MILLISECONDS);
|
|
|
|
+ if (exit) {
|
|
|
|
+ log.info("repeat");
|
|
|
|
+ p = Runtime.getRuntime().exec(cmd);
|
|
|
|
+ } else {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
- return;
|
|
|
|
|
|
+ p = Runtime.getRuntime().exec(cmd);
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- p = Runtime.getRuntime().exec(cmd);
|
|
|
|
}
|
|
}
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
}
|
|
}
|
|
- } catch (Exception e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|