I had a thread that was working, but now that I added some code it doesn't run at all anymore. I tried without the code, and it works. Could someone please have a look at the code and make sure i haven't done anything wrong?
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;
}
I use this to run the code:
Thread tbs = new Thread(new TimedBellServer());
tbs.start();
Thanks
Although the question doesn't provide enough relevant info, I am going to hazard an educated guess here. The question doesn't provide any info about which piece of code was added that is causing the code to not run.
However, since you are not seeing any output at all (the result of the println
statements), and since the second statement in the run
method is a println
, and I am sure that t.start()
is pretty much guaranteed to call the run
method, I think that the line
xbellDB = new DBRefresh().refreshDB();
Is causing an exception. Since your catch
block is catching all the Exceptions
and swallowing them, without any kind of logging, I think you are not able to see any stacktrace or any other relevant info. Try adding something like
System.out.println(e.getMessage())
inside the main catch
block of the run
method and see if it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.