I am using the following code to open connection to SQL database using JDBC
Runnable getConn = new Runnable() {
@Override
public void run() {
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
tracking = true;
activity.run();
} catch (SQLException se) {
se.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
};
Thread connection = new Thread(getConn);
connection.run();
it works but it freezes UI thread till connection is opened. Any ideas on how to move this to separate thread so it wont stop UI thread? I was doing this on android using asyncTask
but I dont know how to do it in Java.