I'm trying to implement a Java Swing GUI App with a game. The game is to count how many times a button is clicked in 5 seconds.
I'm using sqlite4java in one of my Java GUI projects. It is pretty minimalistic therefore supports only single-threaded apps.
I want to execute some SQL query after the 5 seconds is up. I have a Thread started in my button's onclick listener whose run() method is implemented like the following:
run() {
timeLeft = 5;
score = 0;
while(timeLeft>0)
Thread.sleep(100);
timeLeft -= 0.1;
update left time on GUI;
}
// time is up
execute some SQLite INSERT query here;
}
And since sqlite4java is single-thread supported, it throws an exception:
SQLite error:com.almworks.sqlite4java.SQLiteException:
[-98] DB[1] confined(Thread[main,5,]) used (Thread[Thread-3,6,main])
How can I possibly execute after thread is finished (outside the thread)? It is throwing an exception because the callee thread and the thread in which database is instantiated (Main thread) are not the same.
How can I make main thread signaled (and handle this signal in main thread) after this thread terminates?
All I want to achieve is to execute query to add user's score to high scores list. That's not an homework, I'm trying to develop a proof-of-concept application for my own ORM framework.