Recently written an account management software with Java. But when the database is operated, it always causes the JVM downtime. Beginning has always thought that there is a problem with the implementation of database operations. I have written a test program separately to verify that there is no problem in the operation of the database. This makes me a bit very unknown. Since the error is to cause the JVM downtime, there is no prompt about the Java code error. This problem has been plaguing me for a few days, and finally discovered this error after repeated contrast error programs and test programs.
This is my program main () function: public static void main (string args []) {system.setproperty ("swing.plaf.metal.controlfont", "Song"); hmdatabase hmdb = hmdatabasefactory.gethmdatabase (); IF (! hmdb.isok ()) {system.out.println ("Database Open Error!"); return; drugmanage frame = new drugmanage ("drug management)); hmdatabasefactory.closehmdatabase ();} Database action DRUGMANAGE interface is performed.
So I can see the data in the database in the starting interface of DrugManage, but I will cause the database to exit when I have a database on the interface.
The wrong reason is:
DRUGMANAGE derived in JFrame generates a new thread to perform user operations. The original main thread will continue to execute after the DrugManage is constructed. Finally close the database.
So I can read the data in the database when displaying the interface of DrugManage. But when I operate the data in the database in the interface. The MAIN thread has been executed to the last statement, close the database. I still operate the database at this time, of course, the JVM will be overturn, causing the JVM downtime.