我有一个正在运行的线程,但现在我添加了一些它不再运行的代码。我尝试没有代码,它的工作原理。有人可以看看代码并确保我没有做错什么吗?
public class TimeBellServer extends Thread{
static XBellDB[] xbellDB;
static InterviewsDB[] interviewsDB;
static boolean isPaused = false;
static boolean bellsToday = false;
public TimedBellServer() {
}
public void run() {
try {
xbellDB = new DBRefresh().refreshDB();
System.out.println("Cody BAE");
//!this.isInterrupted() &&
while(!TimedBellServer.isPaused) {
SimpleDateFormat format = new SimpleDateFormat("HH:mm");
Date current = new Date();
String formatCurrent = format.format(current);
String date = formatCurrent + ":00";
boolean anyRung = false;
System.out.println("--TimedBellServer: The current system time is: " + date);
if(bellsToday) {
for(int i = 0; i != xbellDB.length; i++) {
if(xbellDB[i].time.equals(date)) {
System.out.println("--TimedBellServer: Ringing bell \"" + xbellDB[i].name + "\"");
TCPConnection.isPaused = true;
GPIO.initiate(18);
Thread.sleep(100);
GPIO.bellOn();
Thread.sleep(8000);
GPIO.bellOff();
Thread.sleep(100);
GPIO.unExport();
TCPConnection.isPaused = false;
}
}
}
if(ParentInterviews.parentInterviewsToday) {
if(interviewsDB[0].value.equals(date)) {
ParentInterviews.isPaused = false;
isPaused = true;
TCPConnection.isPaused = true;
System.out.println("--TimedBellServer: Parent Interviews First Block has started");
}
if(interviewsDB[1].value.equals(date)) {
ParentInterviews.isPaused = true;
TCPConnection.isPaused = false;
System.out.println("--TimedBellServer: Parent Interviews break has started");
}
if(interviewsDB[2].value.equals(date)) {
ParentInterviews.isPaused = false;
TCPConnection.isPaused = true;
System.out.println("--TimedBellServer: Parent Interviews Second Block has started");
}
if(interviewsDB[3].value.equals(date)) {
ParentInterviews.isPaused = true;
TCPConnection.isPaused = false;
isPaused = false;
System.out.println("--TimedBellServer: Parent Interviews Second Block has ended");
}
}
if(date.equals("00:01")) {
ParentInterviews.parentInterviewsToday = false;
}
if(anyRung == false) {System.out.println("--TimedBellServer: No bells rung");}
Thread.sleep(60000);
}
} catch (Exception e) {
}
}
public static void refresh(XBellDB[] db) {
xbellDB = db;
}
public static void refreshInterviews(InterviewsDB[] db) {
interviewsDB = db;
}
我用它来运行代码:
Thread tbs = new Thread(new TimedBellServer());
tbs.start();
由于
答案 0 :(得分:0)
虽然这个问题并没有提供足够的相关信息,但我会冒这个有根据的猜测。该问题并未提供有关添加哪条代码导致代码无法运行的任何信息。
但是,由于您根本没有看到任何输出(println
语句的结果),并且由于run
方法中的第二个语句是println
,因此我我确信t.start()
几乎可以保证调用run
方法,我认为该行
xbellDB = new DBRefresh().refreshDB();
导致异常。由于您的catch
块正在捕获所有Exceptions
并吞下它们,而没有任何记录,我认为您无法看到任何堆栈跟踪或任何其他相关信息。尝试添加类似
System.out.println(e.getMessage())
在catch
方法的主run
块内,看看它是否有帮助。